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

@ -21,11 +21,11 @@ type FeedItem struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
} `xml:"prowlarrindexer"`
Comments string `xml:"comments"`
Size string `xml:"size"`
Link string `xml:"link"`
Category []string `xml:"category,omitempty"`
Categories []string
Comments string `xml:"comments"`
Size string `xml:"size"`
Link string `xml:"link"`
Category []int `xml:"category,omitempty"`
Categories Categories
// attributes
TvdbId string `xml:"tvdb,omitempty"`
@ -33,11 +33,33 @@ type FeedItem struct {
ImdbId string `xml:"imdb,omitempty"`
TmdbId string `xml:"tmdb,omitempty"`
Attributes []struct {
XMLName xml.Name
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
} `xml:"attr"`
Attributes []ItemAttr `xml:"attr"`
}
type ItemAttr struct {
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}
func (f FeedItem) MapCategories(categories []Category) {
for _, category := range f.Category {
// less than 10000 it's default categories
if category < 10000 {
f.Categories = append(f.Categories, ParentCategory(Category{ID: category}))
continue
}
// categories 10000+ are custom tracker specific
for _, capCat := range categories {
if capCat.ID == category {
f.Categories = append(f.Categories, Category{
ID: capCat.ID,
Name: capCat.Name,
})
break
}
}
}
}
// Time credits: https://github.com/mrobinsn/go-newznab/blob/cd89d9c56447859fa1298dc9a0053c92c45ac7ef/newznab/structs.go#L150