feat: better prowlarr support

This commit is contained in:
Simon Ding
2024-11-04 15:10:56 +08:00
parent b176253fc4
commit c17cf750e5
5 changed files with 28 additions and 10 deletions

View File

@@ -12,6 +12,13 @@ import (
"golift.io/starr/prowlarr"
)
type ProwlarrSupportType string
const (
TV ProwlarrSupportType = "tv"
Movie ProwlarrSupportType = "movie"
)
type Client struct {
p *prowlarr.Prowlarr
apiKey string
@@ -24,7 +31,7 @@ func New(apiKey, url string) *Client {
return &Client{p: p, apiKey: apiKey, url: url}
}
func (c *Client) GetIndexers() ([]*db.TorznabInfo, error) {
func (c *Client) GetIndexers(t ProwlarrSupportType) ([]*db.TorznabInfo, error) {
ins, err := c.p.GetIndexers()
if err != nil {
return nil, err
@@ -34,6 +41,11 @@ func (c *Client) GetIndexers() ([]*db.TorznabInfo, error) {
if !in.Enable {
continue
}
if t == "tv" && len(in.Capabilities.TvSearchParams) == 0 { //no tv resource in this indexer
continue
} else if t == "movie" && len(in.Capabilities.MovieSearchParams) == 0 { //no movie resource in this indexer
continue
}
seedRatio := 0.0
for _, f := range in.Fields {
if f.Name == "torrentBaseSettings.seedRatio" && f.Value != nil {
@@ -57,7 +69,7 @@ func (c *Client) GetIndexers() ([]*db.TorznabInfo, error) {
}
indexers = append(indexers, &db.TorznabInfo{
Indexers: &entIndexer,
Indexers: &entIndexer,
TorznabSetting: setting,
})
}

View File

@@ -7,7 +7,7 @@ import (
func Test111(t *testing.T) {
c := New("", "http://10.0.0.8:9696/")
apis , err := c.GetIndexers()
apis , err := c.GetIndexers("tv")
log.Infof("errors: %v", err)
log.Infof("indexers: %+v", apis[0])
}

View File

@@ -85,6 +85,12 @@ func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
// log.Warnf("converting link to magnet error, error: %v, link: %v", err, item.Link)
// continue
// }
imdb := ""
if item.GetAttr("imdbid") != "" {
imdb = item.GetAttr("imdbid")
} else if item.GetAttr("imdb") != "" {
imdb = item.GetAttr("imdb")
}
r := Result{
Name: item.Title,
Link: item.Link,
@@ -92,7 +98,7 @@ func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
Seeders: mustAtoI(item.GetAttr("seeders")),
Peers: mustAtoI(item.GetAttr("peers")),
Category: mustAtoI(item.GetAttr("category")),
ImdbId: item.GetAttr("imdbid"),
ImdbId: imdb,
DownloadVolumeFactor: tryParseFloat(item.GetAttr("downloadvolumefactor")),
UploadVolumeFactor: tryParseFloat(item.GetAttr("uploadvolumefactor")),
Source: indexer.Name,