diff --git a/pkg/metadata/tv.go b/pkg/metadata/tv.go index 188b56e..1667d92 100644 --- a/pkg/metadata/tv.go +++ b/pkg/metadata/tv.go @@ -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 { diff --git a/pkg/transmission/transmission.go b/pkg/transmission/transmission.go index 624b879..a045ec7 100644 --- a/pkg/transmission/transmission.go +++ b/pkg/transmission/transmission.go @@ -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 -} \ No newline at end of file +}