mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-10 03:57:39 +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 {
|
func ParseTv(name string) *Metadata {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
if utils.IsASCII(name) { //english name
|
|
||||||
return parseEnglishName(name)
|
|
||||||
}
|
|
||||||
if utils.ContainsChineseChar(name) {
|
if utils.ContainsChineseChar(name) {
|
||||||
return parseChineseName(name)
|
return parseChineseName(name)
|
||||||
}
|
}
|
||||||
return nil
|
return parseEnglishName(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEnglishName(name string) *Metadata {
|
func parseEnglishName(name string) *Metadata {
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package transmission
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"polaris/log"
|
"polaris/log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hekmon/transmissionrpc/v3"
|
"github.com/hekmon/transmissionrpc/v3"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -39,11 +42,33 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Download(link, dir string) (*Torrent, error) {
|
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{
|
t, err := c.c.TorrentAdd(context.TODO(), transmissionrpc.TorrentAddPayload{
|
||||||
Filename: &link,
|
Filename: &link,
|
||||||
DownloadDir: &dir,
|
DownloadDir: &dir,
|
||||||
})
|
})
|
||||||
log.Infof("get torrent info: %+v", t)
|
log.Infof("get torrent info: %+v", t)
|
||||||
|
if t.ID == nil {
|
||||||
|
return nil, fmt.Errorf("download torrent error: %v", link)
|
||||||
|
}
|
||||||
|
|
||||||
return &Torrent{
|
return &Torrent{
|
||||||
ID: *t.ID,
|
ID: *t.ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user