Skip to content

Commit

Permalink
fix(feeds): parse magnet URI from enclosure (#1514)
Browse files Browse the repository at this point in the history
fix(feeds): parse magnet from enclosure
  • Loading branch information
zze0s committed Apr 19, 2024
1 parent ce17292 commit 56aa7dd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/feed/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"regexp"
"strconv"
"strings"
"time"

"github.com/autobrr/autobrr/internal/domain"
Expand Down Expand Up @@ -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 != "" {
Expand Down
36 changes: 36 additions & 0 deletions internal/feed/rss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 56aa7dd

Please sign in to comment.