diff --git a/internal/feed/rss.go b/internal/feed/rss.go index e7da53b..ce806a4 100644 --- a/internal/feed/rss.go +++ b/internal/feed/rss.go @@ -9,6 +9,7 @@ import ( "net/url" "regexp" "strconv" + "strings" "time" "github.com/autobrr/autobrr/internal/domain" @@ -133,9 +134,16 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release { if e.Type == "application/x-bittorrent" && e.URL != "" { rls.DownloadURL = e.URL } - if e.Length != "" && e.Length != "39399" { + if e.Length != "" && e.Length != "1" && e.Length != "39399" { rls.ParseSizeBytesString(e.Length) } + + if j.Feed.Settings != nil && j.Feed.Settings.DownloadType == domain.FeedDownloadTypeMagnet { + if !strings.HasPrefix(rls.MagnetURI, "magnet:?") && strings.HasPrefix(e.URL, "magnet:?") { + rls.MagnetURI = e.URL + rls.DownloadURL = "" + } + } } if rls.DownloadURL == "" && item.Link != "" { diff --git a/internal/feed/rss_test.go b/internal/feed/rss_test.go index 91e5a01..3f5ef30 100644 --- a/internal/feed/rss_test.go +++ b/internal/feed/rss_test.go @@ -169,6 +169,42 @@ func TestRSSJob_processItem(t *testing.T) { }}, want: nil, }, + { + name: "magnet", + fields: fields{ + Feed: &domain.Feed{ + MaxAge: 3600, + Indexer: domain.IndexerMinimal{ + ID: 0, + Name: "Mock Feed", + Identifier: "mock-feed", + }, + Settings: &domain.FeedSettingsJSON{DownloadType: domain.FeedDownloadTypeMagnet}, + }, + Name: "Magnet feed", + Log: zerolog.Logger{}, + URL: "https://fake-feed.com/rss", + Repo: nil, + ReleaseSvc: nil, + attempts: 0, + errors: nil, + JobID: 0, + }, + args: args{item: &gofeed.Item{ + Title: "Some.Release.Title.2022.09.22.720p.WEB.h264-GROUP", + Description: "Category: Example", + Link: "https://fake-feed.com/details.php?id=00000&hit=1", + GUID: "https://fake-feed.com/details.php?id=00000&hit=1", + Enclosures: []*gofeed.Enclosure{ + { + URL: "magnet:?xt=this-not-a-valid-magnet", + Length: "1", + Type: "application/x-bittorrent", + }, + }, + }}, + want: &domain.Release{ID: 0, FilterStatus: "PENDING", Rejections: []string{}, Indexer: domain.IndexerMinimal{0, "Mock Feed", "mock-feed"}, FilterName: "", Protocol: "torrent", Implementation: "RSS", Timestamp: now, MagnetURI: "magnet:?xt=this-not-a-valid-magnet", 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: 0, Title: "Some Release Title", Description: "Category: Example", 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: "episode", 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)}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {