mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-07 10:37:39 +08:00
feat: support prowlarr connection
This commit is contained in:
@@ -37,6 +37,7 @@ func ParseDoulist(doulistUrl string) (*importlist.Response, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var items []importlist.Item
|
||||
doc.Find("div[class=doulist-item]").Each(func(i int, selection *goquery.Selection) {
|
||||
titleDiv := selection.Find("div[class=title]")
|
||||
link := titleDiv.Find("div>a")
|
||||
@@ -64,18 +65,26 @@ func ParseDoulist(doulistUrl string) (*importlist.Response, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
_, err := parseDetailPage(strings.TrimSpace(href))
|
||||
if err != nil {
|
||||
log.Errorf("get detail page: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
item := importlist.Item{
|
||||
Title: strings.TrimSpace(link.Text()),
|
||||
Year: year,
|
||||
}
|
||||
items = append(items, item)
|
||||
_ = item
|
||||
println(link.Text(), href)
|
||||
//println(link.Text(), href)
|
||||
})
|
||||
return nil, nil
|
||||
|
||||
return &importlist.Response{Items: items}, nil
|
||||
}
|
||||
|
||||
func parseDetailPage(url string) (string, error) {
|
||||
println(url)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -95,6 +104,14 @@ func parseDetailPage(url string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
doc.Find("div[class='subject clearfix']").Each(func(i int, se *goquery.Selection) {
|
||||
println(se.Text())
|
||||
se.Children().Get(1)
|
||||
imdb := se.Find("div[class='info']").First().Children().Last()
|
||||
println(imdb.Text())
|
||||
})
|
||||
|
||||
_ = doc
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ import (
|
||||
)
|
||||
|
||||
func TestParseDoulist(t *testing.T) {
|
||||
r, err := ParseDoulist("https://www.douban.com/doulist/166422/")
|
||||
r, err := ParseDoulist("https://www.douban.com/doulist/81580/")
|
||||
log.Info(r, err)
|
||||
}
|
||||
|
||||
65
pkg/prowlarr/prowlarr.go
Normal file
65
pkg/prowlarr/prowlarr.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package prowlarr
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golift.io/starr"
|
||||
"golift.io/starr/prowlarr"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
p *prowlarr.Prowlarr
|
||||
apiKey string
|
||||
url string
|
||||
}
|
||||
|
||||
func New(apiKey, url string) *Client {
|
||||
c := starr.New(apiKey, url, 10*time.Second)
|
||||
p := prowlarr.New(c)
|
||||
return &Client{p: p, apiKey: apiKey, url: url}
|
||||
}
|
||||
|
||||
func (c *Client) GetIndexers() ([]*db.TorznabInfo, error) {
|
||||
ins, err := c.p.GetIndexers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var indexers []*db.TorznabInfo
|
||||
for _, in := range ins {
|
||||
if !in.Enable {
|
||||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
setting := db.TorznabSetting{
|
||||
URL: fmt.Sprintf("%s/%d/api", strings.TrimSuffix(c.url, "/"), in.ID),
|
||||
ApiKey: c.apiKey,
|
||||
}
|
||||
data, _ := json.Marshal(&setting)
|
||||
|
||||
entIndexer := ent.Indexers{
|
||||
Name: in.Name,
|
||||
Implementation: "torznab",
|
||||
Priority: int(in.Priority),
|
||||
SeedRatio: float32(seedRatio),
|
||||
Settings: string(data),
|
||||
}
|
||||
|
||||
indexers = append(indexers, &db.TorznabInfo{
|
||||
Indexers: &entIndexer,
|
||||
TorznabSetting: setting,
|
||||
})
|
||||
}
|
||||
return indexers, nil
|
||||
}
|
||||
13
pkg/prowlarr/prowlarr_test.go
Normal file
13
pkg/prowlarr/prowlarr_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package prowlarr
|
||||
|
||||
import (
|
||||
"polaris/log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test111(t *testing.T) {
|
||||
c := New("", "http://10.0.0.8:9696/")
|
||||
apis , err := c.GetIndexers()
|
||||
log.Infof("errors: %v", err)
|
||||
log.Infof("indexers: %+v", apis[0])
|
||||
}
|
||||
Reference in New Issue
Block a user