From 1bfbe383356ce91ee63785703450bcc51ce7c8b5 Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Sun, 3 Sep 2023 13:27:47 +0200 Subject: [PATCH] feat(macros): add SizeString DownloadURL and InfoURL (#1080) * feat(macro): add new variables * SizeString * DownloadURL * InfoURL * feat(macro): add new test cases --- internal/action/deluge.go | 4 ++-- internal/action/lidarr.go | 2 +- internal/action/radarr.go | 2 +- internal/action/readarr.go | 2 +- internal/action/sabnzbd.go | 2 +- internal/action/sonarr.go | 2 +- internal/action/whisparr.go | 2 +- internal/announce/announce.go | 2 +- internal/database/release.go | 6 ++--- internal/domain/macros.go | 9 +++++++- internal/domain/macros_test.go | 41 +++++++++++++++++++++++++++------ internal/domain/release.go | 18 +++++++-------- internal/domain/release_test.go | 18 +++++++-------- internal/feed/newznab.go | 2 +- internal/feed/rss.go | 16 ++++++------- internal/feed/rss_test.go | 6 ++--- internal/feed/torznab.go | 4 ++-- 17 files changed, 86 insertions(+), 52 deletions(-) diff --git a/internal/action/deluge.go b/internal/action/deluge.go index 99bc015..91d0498 100644 --- a/internal/action/deluge.go +++ b/internal/action/deluge.go @@ -129,7 +129,7 @@ func (s *service) delugeV1(ctx context.Context, client *domain.DownloadClient, a torrentHash, err := del.AddTorrentMagnet(ctx, release.MagnetURI, &options) if err != nil { - return nil, errors.Wrap(err, "could not add torrent magnet %s to client: %s", release.TorrentURL, client.Name) + return nil, errors.Wrap(err, "could not add torrent magnet %s to client: %s", release.MagnetURI, client.Name) } if action.Label != "" { @@ -242,7 +242,7 @@ func (s *service) delugeV2(ctx context.Context, client *domain.DownloadClient, a torrentHash, err := del.AddTorrentMagnet(ctx, release.MagnetURI, &options) if err != nil { - return nil, errors.Wrap(err, "could not add torrent magnet %s to client: %s", release.TorrentURL, client.Name) + return nil, errors.Wrap(err, "could not add torrent magnet %s to client: %s", release.MagnetURI, client.Name) } if action.Label != "" { diff --git a/internal/action/lidarr.go b/internal/action/lidarr.go index 527280e..b5bece5 100644 --- a/internal/action/lidarr.go +++ b/internal/action/lidarr.go @@ -47,7 +47,7 @@ func (s *service) lidarr(ctx context.Context, action *domain.Action, release dom r := lidarr.Release{ Title: release.TorrentName, - DownloadUrl: release.TorrentURL, + DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, Size: int64(release.Size), Indexer: release.Indexer, diff --git a/internal/action/radarr.go b/internal/action/radarr.go index 8497499..f3aab23 100644 --- a/internal/action/radarr.go +++ b/internal/action/radarr.go @@ -46,7 +46,7 @@ func (s *service) radarr(ctx context.Context, action *domain.Action, release dom r := radarr.Release{ Title: release.TorrentName, - DownloadUrl: release.TorrentURL, + DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, Size: int64(release.Size), Indexer: release.Indexer, diff --git a/internal/action/readarr.go b/internal/action/readarr.go index aa12254..8f50087 100644 --- a/internal/action/readarr.go +++ b/internal/action/readarr.go @@ -46,7 +46,7 @@ func (s *service) readarr(ctx context.Context, action *domain.Action, release do r := readarr.Release{ Title: release.TorrentName, - DownloadUrl: release.TorrentURL, + DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, Size: int64(release.Size), Indexer: release.Indexer, diff --git a/internal/action/sabnzbd.go b/internal/action/sabnzbd.go index 15bf37d..0bc023d 100644 --- a/internal/action/sabnzbd.go +++ b/internal/action/sabnzbd.go @@ -42,7 +42,7 @@ func (s *service) sabnzbd(ctx context.Context, action *domain.Action, release do sab := sabnzbd.New(opts) - ids, err := sab.AddFromUrl(ctx, sabnzbd.AddNzbRequest{Url: release.TorrentURL, Category: action.Category}) + ids, err := sab.AddFromUrl(ctx, sabnzbd.AddNzbRequest{Url: release.DownloadURL, Category: action.Category}) if err != nil { return nil, errors.Wrap(err, "could not add nzb to sabnzbd") } diff --git a/internal/action/sonarr.go b/internal/action/sonarr.go index 6e77751..cd405b1 100644 --- a/internal/action/sonarr.go +++ b/internal/action/sonarr.go @@ -46,7 +46,7 @@ func (s *service) sonarr(ctx context.Context, action *domain.Action, release dom r := sonarr.Release{ Title: release.TorrentName, - DownloadUrl: release.TorrentURL, + DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, Size: int64(release.Size), Indexer: release.Indexer, diff --git a/internal/action/whisparr.go b/internal/action/whisparr.go index f599a38..19daaf8 100644 --- a/internal/action/whisparr.go +++ b/internal/action/whisparr.go @@ -46,7 +46,7 @@ func (s *service) whisparr(ctx context.Context, action *domain.Action, release d r := whisparr.Release{ Title: release.TorrentName, - DownloadUrl: release.TorrentURL, + DownloadUrl: release.DownloadURL, MagnetUrl: release.MagnetURI, Size: int64(release.Size), Indexer: release.Indexer, diff --git a/internal/announce/announce.go b/internal/announce/announce.go index 0c62317..399ed0e 100644 --- a/internal/announce/announce.go +++ b/internal/announce/announce.go @@ -231,7 +231,7 @@ func (a *announceProcessor) onLinesMatched(def *domain.IndexerDefinition, vars m } if matched != nil { - rls.TorrentURL = matched.TorrentURL + rls.DownloadURL = matched.TorrentURL if matched.InfoURL != "" { rls.InfoURL = matched.InfoURL diff --git a/internal/database/release.go b/internal/database/release.go index 9ed4f9e..42dabbd 100644 --- a/internal/database/release.go +++ b/internal/database/release.go @@ -39,7 +39,7 @@ func (repo *ReleaseRepo) Store(ctx context.Context, r *domain.Release) error { queryBuilder := repo.db.squirrel. Insert("release"). Columns("filter_status", "rejections", "indexer", "filter", "protocol", "implementation", "timestamp", "group_id", "torrent_id", "info_url", "download_url", "torrent_name", "size", "title", "category", "season", "episode", "year", "resolution", "source", "codec", "container", "hdr", "release_group", "proper", "repack", "website", "type", "origin", "tags", "uploader", "pre_time", "filter_id"). - Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer, r.FilterName, r.Protocol, r.Implementation, r.Timestamp.Format(time.RFC3339), r.GroupID, r.TorrentID, r.InfoURL, r.TorrentURL, r.TorrentName, r.Size, r.Title, r.Category, r.Season, r.Episode, r.Year, r.Resolution, r.Source, codecStr, r.Container, hdrStr, r.Group, r.Proper, r.Repack, r.Website, r.Type, r.Origin, pq.Array(r.Tags), r.Uploader, r.PreTime, r.FilterID). + Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer, r.FilterName, r.Protocol, r.Implementation, r.Timestamp.Format(time.RFC3339), r.GroupID, r.TorrentID, r.InfoURL, r.DownloadURL, r.TorrentName, r.Size, r.Title, r.Category, r.Season, r.Episode, r.Year, r.Resolution, r.Source, codecStr, r.Container, hdrStr, r.Group, r.Proper, r.Repack, r.Website, r.Type, r.Origin, pq.Array(r.Tags), r.Uploader, r.PreTime, r.FilterID). Suffix("RETURNING id").RunWith(repo.db.handler) // return values @@ -284,7 +284,7 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain rls.FilterName = rlsfilter.String rls.ActionStatus = make([]domain.ReleaseActionStatus, 0) rls.InfoURL = infoUrl.String - rls.TorrentURL = downloadUrl.String + rls.DownloadURL = downloadUrl.String // only add ActionStatus if it's not empty if ras.ID > 0 { @@ -436,7 +436,7 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest) rls.FilterID = int(filterId.Int64) rls.ActionStatus = make([]domain.ReleaseActionStatus, 0) rls.InfoURL = infoUrl.String - rls.TorrentURL = downloadUrl.String + rls.DownloadURL = downloadUrl.String rls.Category = category.String rls.GroupID = groupId.String rls.TorrentID = torrentId.String diff --git a/internal/domain/macros.go b/internal/domain/macros.go index 3f6a36c..bfaa826 100644 --- a/internal/domain/macros.go +++ b/internal/domain/macros.go @@ -12,6 +12,7 @@ import ( "github.com/autobrr/autobrr/pkg/errors" "github.com/Masterminds/sprig/v3" + "github.com/dustin/go-humanize" ) type Macro struct { @@ -23,6 +24,8 @@ type Macro struct { TorrentDataRawBytes []byte MagnetURI string GroupID string + DownloadUrl string + InfoUrl string Indexer string Title string Category string @@ -32,6 +35,7 @@ type Macro struct { HDR string FilterName string Size uint64 + SizeString string Season int Episode int Year int @@ -48,13 +52,15 @@ func NewMacro(release Release) Macro { ma := Macro{ TorrentName: release.TorrentName, - TorrentUrl: release.TorrentURL, + TorrentUrl: release.DownloadURL, TorrentPathName: release.TorrentTmpFile, TorrentDataRawBytes: release.TorrentDataRawBytes, TorrentHash: release.TorrentHash, TorrentID: release.TorrentID, MagnetURI: release.MagnetURI, GroupID: release.GroupID, + InfoUrl: release.InfoURL, + DownloadUrl: release.DownloadURL, Indexer: release.Indexer, Title: release.Title, Category: release.Category, @@ -64,6 +70,7 @@ func NewMacro(release Release) Macro { HDR: strings.Join(release.HDR, ", "), FilterName: release.FilterName, Size: release.Size, + SizeString: humanize.Bytes(release.Size), Season: release.Season, Episode: release.Episode, Year: release.Year, diff --git a/internal/domain/macros_test.go b/internal/domain/macros_test.go index 329edd5..77187d3 100644 --- a/internal/domain/macros_test.go +++ b/internal/domain/macros_test.go @@ -89,7 +89,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_args_long", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", }, args: args{text: "{{.TorrentName}} {{.TorrentUrl}} SOME_LONG_TOKEN"}, @@ -100,7 +100,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_args_long_1", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", }, args: args{text: "{{.Indexer}} {{.TorrentName}} {{.TorrentUrl}} SOME_LONG_TOKEN"}, @@ -111,7 +111,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_args_category", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", }, args: args{text: "{{.Indexer}}-race"}, @@ -122,7 +122,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_args_category_year", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", }, args: args{text: "{{.Indexer}}-{{.CurrentYear}}-race"}, @@ -133,7 +133,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_args_category_year", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", Resolution: "2160p", HDR: []string{"DV"}, @@ -146,7 +146,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_args_category_and_if", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", Resolution: "2160p", HDR: []string{"HDR"}, @@ -159,7 +159,7 @@ func TestMacros_Parse(t *testing.T) { name: "test_release_year_1", release: Release{ TorrentName: "This movie 2021", - TorrentURL: "https://some.site/download/fakeid", + DownloadURL: "https://some.site/download/fakeid", Indexer: "mock1", Resolution: "2160p", HDR: []string{"HDR"}, @@ -178,6 +178,15 @@ func TestMacros_Parse(t *testing.T) { want: "3.57 GB", wantErr: false, }, + { + name: "test_size_string", + release: Release{ + Size: 3834225472, + }, + args: args{text: "Size: {{ .SizeString }}"}, + want: "Size: 3.8 GB", + wantErr: false, + }, { name: "test_text_manipulation", release: Release{ @@ -187,6 +196,24 @@ func TestMacros_Parse(t *testing.T) { want: "[Blu-ray][MKV][h264 10-bit][1080p][FLAC 2.0][Dual Audio][Softsubs (Sub Group)][Freeleech]", wantErr: false, }, + { + name: "test_info_url", + release: Release{ + InfoURL: "https://test.local/this/page", + }, + args: args{text: "InfoUrl: {{ .InfoUrl }}"}, + want: "InfoUrl: https://test.local/this/page", + wantErr: false, + }, + { + name: "test_download_url", + release: Release{ + DownloadURL: "https://test.local/this/page/1001", + }, + args: args{text: "DownloadUrl: {{ .DownloadUrl }}"}, + want: "DownloadUrl: https://test.local/this/page/1001", + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/domain/release.go b/internal/domain/release.go index ed88ca6..6db37de 100644 --- a/internal/domain/release.go +++ b/internal/domain/release.go @@ -52,7 +52,7 @@ type Release struct { Implementation ReleaseImplementation `json:"implementation"` // irc, rss, api Timestamp time.Time `json:"timestamp"` InfoURL string `json:"info_url"` - TorrentURL string `json:"download_url"` + DownloadURL string `json:"download_url"` MagnetURI string `json:"-"` GroupID string `json:"group_id"` TorrentID string `json:"torrent_id"` @@ -374,7 +374,7 @@ func (r *Release) downloadTorrentFile(ctx context.Context) error { return errors.New("could not download file: protocol %s is not supported", r.Protocol) } - if r.TorrentURL == "" { + if r.DownloadURL == "" { return errors.New("download_file: url can't be empty") } else if r.TorrentTmpFile != "" { // already downloaded @@ -388,7 +388,7 @@ func (r *Release) downloadTorrentFile(ctx context.Context) error { Timeout: time.Second * 45, } - req, err := http.NewRequestWithContext(ctx, http.MethodGet, r.TorrentURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, r.DownloadURL, nil) if err != nil { return errors.Wrap(err, "error downloading file") } @@ -428,22 +428,22 @@ func (r *Release) downloadTorrentFile(ctx context.Context) error { // Continue processing the response //case http.StatusMovedPermanently, http.StatusFound, http.StatusSeeOther, http.StatusTemporaryRedirect, http.StatusPermanentRedirect: // // Handle redirect - // return retry.Unrecoverable(errors.New("redirect encountered for torrent (%v) file (%v) - status code: %d - check indexer keys for %s", r.TorrentName, r.TorrentURL, resp.StatusCode, r.Indexer)) + // return retry.Unrecoverable(errors.New("redirect encountered for torrent (%s) file (%s) - status code: %d - check indexer keys for %s", r.TorrentName, r.DownloadURL, resp.StatusCode, r.Indexer)) case http.StatusUnauthorized, http.StatusForbidden: - return retry.Unrecoverable(errors.New("unrecoverable error downloading torrent (%v) file (%v) - status code: %d - check indexer keys for %s", r.TorrentName, r.TorrentURL, resp.StatusCode, r.Indexer)) + return retry.Unrecoverable(errors.New("unrecoverable error downloading torrent (%s) file (%s) - status code: %d - check indexer keys for %s", r.TorrentName, r.DownloadURL, resp.StatusCode, r.Indexer)) case http.StatusMethodNotAllowed: - return retry.Unrecoverable(errors.New("unrecoverable error downloading torrent (%v) file (%v) from '%v' - status code: %d. Check if the request method is correct", r.TorrentName, r.TorrentURL, r.Indexer, resp.StatusCode)) + return retry.Unrecoverable(errors.New("unrecoverable error downloading torrent (%s) file (%s) from '%s' - status code: %d. Check if the request method is correct", r.TorrentName, r.DownloadURL, r.Indexer, resp.StatusCode)) case http.StatusNotFound: return errors.New("torrent %s not found on %s (%d) - retrying", r.TorrentName, r.Indexer, resp.StatusCode) case http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout: - return errors.New("server error (%d) encountered while downloading torrent (%v) file (%v) from '%v' - retrying", resp.StatusCode, r.TorrentName, r.TorrentURL, r.Indexer) + return errors.New("server error (%d) encountered while downloading torrent (%s) file (%s) from '%s' - retrying", resp.StatusCode, r.TorrentName, r.DownloadURL, r.Indexer) case http.StatusInternalServerError: - return errors.New("server error (%d) encountered while downloading torrent (%v) file (%v) - check indexer keys for %s", resp.StatusCode, r.TorrentName, r.TorrentURL, r.Indexer) + return errors.New("server error (%d) encountered while downloading torrent (%s) file (%s) - check indexer keys for %s", resp.StatusCode, r.TorrentName, r.DownloadURL, r.Indexer) default: return retry.Unrecoverable(errors.New("unexpected status code %d: check indexer keys for %s", resp.StatusCode, r.Indexer)) @@ -686,7 +686,7 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro if torrentSize, err := getStringMapValue(varMap, "torrentSize"); err == nil { // handling for indexer who doesn't explicitly set which size unit is used like (AR) if def.IRC != nil && def.IRC.Parse != nil && def.IRC.Parse.ForceSizeUnit != "" { - torrentSize = fmt.Sprintf("%v %v", torrentSize, def.IRC.Parse.ForceSizeUnit) + torrentSize = fmt.Sprintf("%s %s", torrentSize, def.IRC.Parse.ForceSizeUnit) } size, err := humanize.ParseBytes(torrentSize) diff --git a/internal/domain/release_test.go b/internal/domain/release_test.go index 54d1443..44c46cb 100644 --- a/internal/domain/release_test.go +++ b/internal/domain/release_test.go @@ -620,7 +620,7 @@ func TestRelease_ParseString(t *testing.T) { Timestamp: tt.fields.Timestamp, GroupID: tt.fields.GroupID, TorrentID: tt.fields.TorrentID, - TorrentURL: tt.fields.TorrentURL, + DownloadURL: tt.fields.DownloadURL, TorrentTmpFile: tt.fields.TorrentTmpFile, TorrentHash: tt.fields.TorrentHash, TorrentName: tt.fields.TorrentName, @@ -746,7 +746,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { Timestamp time.Time GroupID string TorrentID string - TorrentURL string + DownloadURL string TorrentTmpFile string TorrentDataRawBytes []byte TorrentHash string @@ -799,7 +799,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { fields: fields{ Indexer: "mock-indexer", TorrentName: "Test.Release-GROUP", - TorrentURL: fmt.Sprintf("%s/%d", ts.URL, 401), + DownloadURL: fmt.Sprintf("%s/%d", ts.URL, 401), Protocol: ReleaseProtocolTorrent, }, wantErr: true, @@ -809,7 +809,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { fields: fields{ Indexer: "mock-indexer", TorrentName: "Test.Release-GROUP", - TorrentURL: fmt.Sprintf("%s/%d", ts.URL, 403), + DownloadURL: fmt.Sprintf("%s/%d", ts.URL, 403), Protocol: ReleaseProtocolTorrent, }, wantErr: true, @@ -819,7 +819,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { fields: fields{ Indexer: "mock-indexer", TorrentName: "Test.Release-GROUP", - TorrentURL: fmt.Sprintf("%s/%d", ts.URL, 500), + DownloadURL: fmt.Sprintf("%s/%d", ts.URL, 500), Protocol: ReleaseProtocolTorrent, }, wantErr: true, @@ -829,7 +829,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { fields: fields{ Indexer: "mock-indexer", TorrentName: "Test.Release-GROUP", - TorrentURL: fmt.Sprintf("%s/%s", ts.URL, "file.torrent"), + DownloadURL: fmt.Sprintf("%s/%s", ts.URL, "file.torrent"), Protocol: ReleaseProtocolTorrent, }, wantErr: false, @@ -839,7 +839,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { fields: fields{ Indexer: "mock-indexer", TorrentName: "Test.Release-GROUP", - TorrentURL: fmt.Sprintf("%s/files/%s", ts.URL, "valid_torrent_as_html"), + DownloadURL: fmt.Sprintf("%s/files/%s", ts.URL, "valid_torrent_as_html"), Protocol: ReleaseProtocolTorrent, }, wantErr: false, @@ -849,7 +849,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { fields: fields{ Indexer: "mock-indexer", TorrentName: "Test.Release-GROUP", - TorrentURL: fmt.Sprintf("%s/files/%s", ts.URL, "invalid_torrent_as_html"), + DownloadURL: fmt.Sprintf("%s/files/%s", ts.URL, "invalid_torrent_as_html"), Protocol: ReleaseProtocolTorrent, }, wantErr: true, @@ -869,7 +869,7 @@ func TestRelease_DownloadTorrentFile(t *testing.T) { Timestamp: tt.fields.Timestamp, GroupID: tt.fields.GroupID, TorrentID: tt.fields.TorrentID, - TorrentURL: tt.fields.TorrentURL, + DownloadURL: tt.fields.DownloadURL, TorrentTmpFile: tt.fields.TorrentTmpFile, TorrentDataRawBytes: tt.fields.TorrentDataRawBytes, TorrentHash: tt.fields.TorrentHash, diff --git a/internal/feed/newznab.go b/internal/feed/newznab.go index 30c248e..688216d 100644 --- a/internal/feed/newznab.go +++ b/internal/feed/newznab.go @@ -102,7 +102,7 @@ func (j *NewznabJob) process(ctx context.Context) error { if item.Enclosure != nil { if item.Enclosure.Type == "application/x-nzb" { - rls.TorrentURL = item.Enclosure.Url + rls.DownloadURL = item.Enclosure.Url } } diff --git a/internal/feed/rss.go b/internal/feed/rss.go index 676f1a0..b4ef7bf 100644 --- a/internal/feed/rss.go +++ b/internal/feed/rss.go @@ -112,33 +112,33 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release { if j.Feed.Settings != nil && j.Feed.Settings.DownloadType == domain.FeedDownloadTypeMagnet { rls.MagnetURI = item.Link - rls.TorrentURL = "" + rls.DownloadURL = "" } if len(item.Enclosures) > 0 { e := item.Enclosures[0] if e.Type == "application/x-bittorrent" && e.URL != "" { - rls.TorrentURL = e.URL + rls.DownloadURL = e.URL } if e.Length != "" && e.Length != "39399" { rls.ParseSizeBytesString(e.Length) } } - if rls.TorrentURL == "" && item.Link != "" { - rls.TorrentURL = item.Link + if rls.DownloadURL == "" && item.Link != "" { + rls.DownloadURL = item.Link } - if rls.TorrentURL != "" { + if rls.DownloadURL != "" { // handle no baseurl with only relative url // grab url from feed url and create full url - if parsedURL, _ := url.Parse(rls.TorrentURL); parsedURL != nil && len(parsedURL.Hostname()) == 0 { + if parsedURL, _ := url.Parse(rls.DownloadURL); parsedURL != nil && len(parsedURL.Hostname()) == 0 { if parentURL, _ := url.Parse(j.URL); parentURL != nil { parentURL.Path, parentURL.RawPath = "", "" // unescape the query params for max compatibility - escapedUrl, _ := url.QueryUnescape(parentURL.JoinPath(rls.TorrentURL).String()) - rls.TorrentURL = escapedUrl + escapedUrl, _ := url.QueryUnescape(parentURL.JoinPath(rls.DownloadURL).String()) + rls.DownloadURL = escapedUrl } } } diff --git a/internal/feed/rss_test.go b/internal/feed/rss_test.go index 76ebf1d..82f02fb 100644 --- a/internal/feed/rss_test.go +++ b/internal/feed/rss_test.go @@ -67,7 +67,7 @@ func TestRSSJob_processItem(t *testing.T) { Link: "/details.php?id=00000&hit=1", GUID: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", }}, - want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: "mock-feed", FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, GroupID: "", TorrentID: "", TorrentURL: "https://fake-feed.com/details.php?id=00000&hit=1", TorrentTmpFile: "", TorrentDataRawBytes: []uint8(nil), TorrentHash: "", TorrentName: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", Size: 0x0, Title: "Some Release Title", Description: "Category: Example\n Size: 1.49 GB\n Status: 27 seeders and 1 leechers\n Speed: 772.16 kB/s\n Added: 2022-09-29 16:06:08\n", Category: "", Season: 0, Episode: 0, Year: 2022, Resolution: "720p", Source: "WEB", Codec: []string{"H.264"}, Container: "", HDR: []string(nil), Audio: []string(nil), AudioChannels: "", Group: "GROUP", Region: "", Language: nil, Proper: false, Repack: false, Website: "", Artists: "", Type: "", LogScore: 0, Origin: "", Tags: []string{}, ReleaseTags: "", Freeleech: false, FreeleechPercent: 0, Bonus: []string(nil), Uploader: "", PreTime: "", Other: []string(nil), RawCookie: "", AdditionalSizeCheckRequired: false, FilterID: 0, Filter: (*domain.Filter)(nil), ActionStatus: []domain.ReleaseActionStatus(nil)}, + want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: "mock-feed", FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, GroupID: "", TorrentID: "", DownloadURL: "https://fake-feed.com/details.php?id=00000&hit=1", TorrentTmpFile: "", TorrentDataRawBytes: []uint8(nil), TorrentHash: "", TorrentName: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", Size: 0x0, Title: "Some Release Title", Description: "Category: Example\n Size: 1.49 GB\n Status: 27 seeders and 1 leechers\n Speed: 772.16 kB/s\n Added: 2022-09-29 16:06:08\n", Category: "", Season: 0, Episode: 0, Year: 2022, Resolution: "720p", Source: "WEB", Codec: []string{"H.264"}, Container: "", HDR: []string(nil), Audio: []string(nil), AudioChannels: "", Group: "GROUP", Region: "", Language: nil, Proper: false, Repack: false, Website: "", Artists: "", Type: "", LogScore: 0, Origin: "", Tags: []string{}, ReleaseTags: "", Freeleech: false, FreeleechPercent: 0, Bonus: []string(nil), Uploader: "", PreTime: "", Other: []string(nil), RawCookie: "", AdditionalSizeCheckRequired: false, FilterID: 0, Filter: (*domain.Filter)(nil), ActionStatus: []domain.ReleaseActionStatus(nil)}, }, { name: "with_baseurl", @@ -96,7 +96,7 @@ func TestRSSJob_processItem(t *testing.T) { Link: "https://fake-feed.com/details.php?id=00000&hit=1", GUID: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", }}, - want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: "mock-feed", FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, GroupID: "", TorrentID: "", TorrentURL: "https://fake-feed.com/details.php?id=00000&hit=1", TorrentTmpFile: "", TorrentDataRawBytes: []uint8(nil), TorrentHash: "", TorrentName: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", Size: 0x0, Title: "Some Release Title", Description: "Category: Example\n Size: 1.49 GB\n Status: 27 seeders and 1 leechers\n Speed: 772.16 kB/s\n Added: 2022-09-29 16:06:08\n", Category: "", Season: 0, Episode: 0, Year: 2022, Resolution: "720p", Source: "WEB", Codec: []string{"H.264"}, Container: "", HDR: []string(nil), Audio: []string(nil), AudioChannels: "", Group: "GROUP", Region: "", Language: nil, Proper: false, Repack: false, Website: "", Artists: "", Type: "", LogScore: 0, Origin: "", Tags: []string{}, ReleaseTags: "", Freeleech: false, FreeleechPercent: 0, Bonus: []string(nil), Uploader: "", PreTime: "", Other: []string(nil), RawCookie: "", AdditionalSizeCheckRequired: false, FilterID: 0, Filter: (*domain.Filter)(nil), ActionStatus: []domain.ReleaseActionStatus(nil)}, + want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: "mock-feed", FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, GroupID: "", TorrentID: "", DownloadURL: "https://fake-feed.com/details.php?id=00000&hit=1", TorrentTmpFile: "", TorrentDataRawBytes: []uint8(nil), TorrentHash: "", TorrentName: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", Size: 0x0, Title: "Some Release Title", Description: "Category: Example\n Size: 1.49 GB\n Status: 27 seeders and 1 leechers\n Speed: 772.16 kB/s\n Added: 2022-09-29 16:06:08\n", Category: "", Season: 0, Episode: 0, Year: 2022, Resolution: "720p", Source: "WEB", Codec: []string{"H.264"}, Container: "", HDR: []string(nil), Audio: []string(nil), AudioChannels: "", Group: "GROUP", Region: "", Language: nil, Proper: false, Repack: false, Website: "", Artists: "", Type: "", LogScore: 0, Origin: "", Tags: []string{}, ReleaseTags: "", Freeleech: false, FreeleechPercent: 0, Bonus: []string(nil), Uploader: "", PreTime: "", Other: []string(nil), RawCookie: "", AdditionalSizeCheckRequired: false, FilterID: 0, Filter: (*domain.Filter)(nil), ActionStatus: []domain.ReleaseActionStatus(nil)}, }, { name: "time_parse", @@ -126,7 +126,7 @@ func TestRSSJob_processItem(t *testing.T) { GUID: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", //PublishedParsed: &nowMinusTime, }}, - want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: "mock-feed", FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, GroupID: "", TorrentID: "", TorrentURL: "https://fake-feed.com/details.php?id=00000&hit=1", TorrentTmpFile: "", TorrentDataRawBytes: []uint8(nil), TorrentHash: "", TorrentName: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", Size: 0x0, Title: "Some Release Title", Description: "Category: Example\n Size: 1.49 GB\n Status: 27 seeders and 1 leechers\n Speed: 772.16 kB/s\n Added: 2022-09-29 16:06:08\n", Category: "", Season: 0, Episode: 0, Year: 2022, Resolution: "720p", Source: "WEB", Codec: []string{"H.264"}, Container: "", HDR: []string(nil), Audio: []string(nil), AudioChannels: "", Group: "GROUP", Region: "", Language: nil, Proper: false, Repack: false, Website: "", Artists: "", Type: "", LogScore: 0, Origin: "", Tags: []string{}, ReleaseTags: "", Freeleech: false, FreeleechPercent: 0, Bonus: []string(nil), Uploader: "", PreTime: "", Other: []string(nil), RawCookie: "", AdditionalSizeCheckRequired: false, FilterID: 0, Filter: (*domain.Filter)(nil), ActionStatus: []domain.ReleaseActionStatus(nil)}, + want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: "mock-feed", FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, GroupID: "", TorrentID: "", DownloadURL: "https://fake-feed.com/details.php?id=00000&hit=1", TorrentTmpFile: "", TorrentDataRawBytes: []uint8(nil), TorrentHash: "", TorrentName: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", Size: 0x0, Title: "Some Release Title", Description: "Category: Example\n Size: 1.49 GB\n Status: 27 seeders and 1 leechers\n Speed: 772.16 kB/s\n Added: 2022-09-29 16:06:08\n", Category: "", Season: 0, Episode: 0, Year: 2022, Resolution: "720p", Source: "WEB", Codec: []string{"H.264"}, Container: "", HDR: []string(nil), Audio: []string(nil), AudioChannels: "", Group: "GROUP", Region: "", Language: nil, Proper: false, Repack: false, Website: "", Artists: "", Type: "", LogScore: 0, Origin: "", Tags: []string{}, ReleaseTags: "", Freeleech: false, FreeleechPercent: 0, Bonus: []string(nil), Uploader: "", PreTime: "", Other: []string(nil), RawCookie: "", AdditionalSizeCheckRequired: false, FilterID: 0, Filter: (*domain.Filter)(nil), ActionStatus: []domain.ReleaseActionStatus(nil)}, }, { name: "time_parse", diff --git a/internal/feed/torznab.go b/internal/feed/torznab.go index 103fcd8..921b2e4 100644 --- a/internal/feed/torznab.go +++ b/internal/feed/torznab.go @@ -92,7 +92,7 @@ func (j *TorznabJob) process(ctx context.Context) error { rls := domain.NewRelease(j.IndexerIdentifier) rls.TorrentName = item.Title - rls.TorrentURL = item.Link + rls.DownloadURL = item.Link rls.Implementation = domain.ReleaseImplementationTorznab // parse size bytes string @@ -102,7 +102,7 @@ func (j *TorznabJob) process(ctx context.Context) error { if j.Feed.Settings != nil && j.Feed.Settings.DownloadType == domain.FeedDownloadTypeMagnet { rls.MagnetURI = item.Link - rls.TorrentURL = "" + rls.DownloadURL = "" } // Get freeleech percentage between 0 - 100. The value is ignored if