feat(filters): implement min and max seeders/leechers filtering for Torznab feeds (#1342)

* feat(filter):implement min and max seeders/leechers filtering

* chore: go fmt and reorder fields

---------

Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
luckyboy 2024-01-13 00:08:18 +08:00 committed by GitHub
parent 256fbb49ba
commit a86258aaa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 192 additions and 3 deletions

View file

@ -114,6 +114,18 @@ func (j *TorznabJob) process(ctx context.Context) error {
rls.ParseString(item.Title)
rls.Seeders, err = parseIntAttribute(item, "seeders")
if err != nil {
rls.Seeders = 0
}
var peers, err = parseIntAttribute(item, "peers")
rls.Leechers = peers - rls.Seeders
if err != nil {
rls.Leechers = 0
}
if j.Feed.Settings != nil && j.Feed.Settings.DownloadType == domain.FeedDownloadTypeMagnet {
rls.MagnetURI = item.Link
rls.DownloadURL = ""
@ -152,6 +164,20 @@ func (j *TorznabJob) process(ctx context.Context) error {
return nil
}
func parseIntAttribute(item torznab.FeedItem, attrName string) (int, error) {
for _, attr := range item.Attributes {
if attr.Name == attrName {
// Parse the value as decimal number
intValue, err := strconv.Atoi(attr.Value)
if err != nil {
return 0, err
}
return intValue, err
}
}
return 0, nil
}
// Parse the downloadvolumefactor attribute. The returned value is the percentage
// of downloaded data that does NOT count towards a user's total download amount.
func parseFreeleechTorznab(item torznab.FeedItem) (int, error) {