feat(feeds): torznab parse category and freeleech (#492)

* feat(feeds): torznab parse freeleech

* feat(feeds): torznab parse categories
This commit is contained in:
ze0s 2022-10-14 18:01:04 +02:00 committed by GitHub
parent 924899d9f3
commit b7d2161fdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 478 additions and 57 deletions

View file

@ -2,6 +2,7 @@ package feed
import (
"sort"
"strconv"
"time"
"github.com/autobrr/autobrr/internal/domain"
@ -79,6 +80,17 @@ func (j *TorznabJob) process() error {
rls.ParseString(item.Title)
if parseFreeleech(item) {
rls.Freeleech = true
rls.Bonus = []string{"Freeleech"}
}
// map torznab categories ID and Name into rls.Categories
// so we can filter on both ID and Name
for _, category := range item.Categories {
rls.Categories = append(rls.Categories, []string{category.Name, strconv.Itoa(category.ID)}...)
}
releases = append(releases, rls)
}
@ -88,9 +100,21 @@ func (j *TorznabJob) process() error {
return nil
}
func parseFreeleech(item torznab.FeedItem) bool {
for _, attr := range item.Attributes {
if attr.Name == "downloadvolumefactor" {
if attr.Value == "0" {
return true
}
}
}
return false
}
func (j *TorznabJob) getFeed() ([]torznab.FeedItem, error) {
// get feed
feedItems, err := j.Client.GetFeed()
feedItems, err := j.Client.FetchFeed()
if err != nil {
j.Log.Error().Err(err).Msgf("error fetching feed items")
return nil, errors.Wrap(err, "error fetching feed items")