mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
feat: follow jackett redirect to get real link
This commit is contained in:
@@ -19,13 +19,10 @@ type Metadata struct {
|
||||
|
||||
func ParseTv(name string) *Metadata {
|
||||
name = strings.ToLower(name)
|
||||
if utils.IsASCII(name) { //english name
|
||||
return parseEnglishName(name)
|
||||
}
|
||||
if utils.ContainsChineseChar(name) {
|
||||
return parseChineseName(name)
|
||||
}
|
||||
return nil
|
||||
return parseEnglishName(name)
|
||||
}
|
||||
|
||||
func parseEnglishName(name string) *Metadata {
|
||||
|
||||
@@ -3,8 +3,11 @@ package transmission
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"polaris/log"
|
||||
"strings"
|
||||
|
||||
"github.com/hekmon/transmissionrpc/v3"
|
||||
"github.com/pkg/errors"
|
||||
@@ -34,20 +37,42 @@ type Config struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
type Client struct {
|
||||
c *transmissionrpc.Client
|
||||
c *transmissionrpc.Client
|
||||
cfg Config
|
||||
}
|
||||
|
||||
func (c *Client) Download(link, dir string) (*Torrent, error) {
|
||||
if strings.HasPrefix(link, "http") {
|
||||
client := &http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
}
|
||||
resp, err:=client.Get(link)
|
||||
if err == nil {
|
||||
if resp.StatusCode == http.StatusFound {
|
||||
loc, err := resp.Location()
|
||||
if err == nil {
|
||||
link = loc.String()
|
||||
log.Warnf("transimision redirect to url: %v", link)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
t, err := c.c.TorrentAdd(context.TODO(), transmissionrpc.TorrentAddPayload{
|
||||
Filename: &link,
|
||||
DownloadDir: &dir,
|
||||
})
|
||||
log.Infof("get torrent info: %+v", t)
|
||||
if t.ID == nil {
|
||||
return nil, fmt.Errorf("download torrent error: %v", link)
|
||||
}
|
||||
|
||||
return &Torrent{
|
||||
ID: *t.ID,
|
||||
c: c.c,
|
||||
ID: *t.ID,
|
||||
c: c.c,
|
||||
Config: c.cfg,
|
||||
}, err
|
||||
}
|
||||
@@ -95,7 +120,7 @@ func (t *Torrent) Progress() int {
|
||||
if t.getTorrent().PercentComplete != nil && *t.getTorrent().PercentComplete >= 1 {
|
||||
return 100
|
||||
}
|
||||
|
||||
|
||||
if t.getTorrent().PercentComplete != nil {
|
||||
p := int(*t.getTorrent().PercentComplete * 100)
|
||||
if p == 100 {
|
||||
@@ -143,4 +168,4 @@ func ReloadTorrent(s string) (*Torrent, error) {
|
||||
return nil, errors.Wrap(err, "reload client")
|
||||
}
|
||||
return &torrent, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user