mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-30 14:37:42 +08:00
feat: prowlarr refactor and support prowlarr seed ratio
This commit is contained in:
@@ -31,26 +31,28 @@ func New(apiKey, url string) *Client {
|
||||
return &Client{p: p, apiKey: apiKey, url: url}
|
||||
}
|
||||
|
||||
func (c *Client) GetIndexers(t ProwlarrSupportType) ([]*db.TorznabInfo, error) {
|
||||
func (c *Client) GetIndexers() ([]*ent.Indexers, error) {
|
||||
ins, err := c.p.GetIndexers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var indexers []*db.TorznabInfo
|
||||
var indexers []*ent.Indexers
|
||||
for _, in := range ins {
|
||||
if !in.Enable {
|
||||
continue
|
||||
|
||||
tvSearch := true
|
||||
movieSearch := true
|
||||
if len(in.Capabilities.TvSearchParams) == 0 { //no tv resource in this indexer
|
||||
tvSearch = false
|
||||
}
|
||||
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
|
||||
if len(in.Capabilities.MovieSearchParams) == 0 { //no movie resource in this indexer
|
||||
movieSearch = false
|
||||
}
|
||||
seedRatio := 0.0
|
||||
for _, f := range in.Fields {
|
||||
if f.Name == "torrentBaseSettings.seedRatio" && f.Value != nil {
|
||||
if r, ok := f.Value.(float64); ok {
|
||||
seedRatio = r
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,17 +63,18 @@ func (c *Client) GetIndexers(t ProwlarrSupportType) ([]*db.TorznabInfo, error) {
|
||||
data, _ := json.Marshal(&setting)
|
||||
|
||||
entIndexer := ent.Indexers{
|
||||
Disabled: !in.Enable,
|
||||
Name: in.Name,
|
||||
Implementation: "torznab",
|
||||
Priority: 128 - int(in.Priority),
|
||||
SeedRatio: float32(seedRatio),
|
||||
Settings: string(data),
|
||||
TvSearch: tvSearch,
|
||||
MovieSearch: movieSearch,
|
||||
APIKey: c.apiKey,
|
||||
URL: fmt.Sprintf("%s/%d/api", strings.TrimSuffix(c.url, "/"), in.ID),
|
||||
}
|
||||
|
||||
indexers = append(indexers, &db.TorznabInfo{
|
||||
Indexers: &entIndexer,
|
||||
TorznabSetting: setting,
|
||||
})
|
||||
indexers = append(indexers, &entIndexer)
|
||||
}
|
||||
return indexers, nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
func Test111(t *testing.T) {
|
||||
c := New("", "http://10.0.0.8:9696/")
|
||||
apis , err := c.GetIndexers("tv")
|
||||
apis , err := c.GetIndexers()
|
||||
log.Infof("errors: %v", err)
|
||||
log.Infof("indexers: %+v", apis[0])
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/log"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -74,7 +74,7 @@ func (i *Item) GetAttr(key string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
|
||||
func (r *Response) ToResults(indexer *ent.Indexers) []Result {
|
||||
var res []Result
|
||||
for _, item := range r.Channel.Item {
|
||||
if slices.Contains(item.Category, "3000") { //exclude audio files
|
||||
@@ -130,7 +130,7 @@ func tryParseFloat(s string) float32 {
|
||||
return float32(r)
|
||||
}
|
||||
|
||||
func Search(indexer *db.TorznabInfo, keyWord string) ([]Result, error) {
|
||||
func Search(indexer *ent.Indexers, keyWord string) ([]Result, error) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -139,7 +139,7 @@ func Search(indexer *db.TorznabInfo, keyWord string) ([]Result, error) {
|
||||
return nil, errors.Wrap(err, "new request")
|
||||
}
|
||||
var q = url.Values{}
|
||||
q.Add("apikey", indexer.ApiKey)
|
||||
q.Add("apikey", indexer.APIKey)
|
||||
q.Add("t", "search")
|
||||
q.Add("q", keyWord)
|
||||
req.URL.RawQuery = q.Encode()
|
||||
@@ -183,7 +183,7 @@ type Result struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Link string `json:"link"`
|
||||
Size int64 `json:"size"`
|
||||
Size int64 `json:"size"`
|
||||
Seeders int `json:"seeders"`
|
||||
Peers int `json:"peers"`
|
||||
Category int `json:"category"`
|
||||
|
||||
Reference in New Issue
Block a user