mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-08 11:07:42 +08:00
basic find download ability
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
package downloader
|
||||
|
||||
import (
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func DownloadByMagnet(magnet string, dir string) (*torrent.Torrent, error) {
|
||||
c, err := torrent.NewClient(nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "new torrent")
|
||||
}
|
||||
defer c.Close()
|
||||
t, err := c.AddMagnet(magnet)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add torrent")
|
||||
}
|
||||
|
||||
<-t.GotInfo()
|
||||
t.DownloadAll()
|
||||
c.WaitAll()
|
||||
return t, nil
|
||||
}
|
||||
@@ -36,6 +36,11 @@ func (c *Client) SearchTvShow(query string, lang string) (*tmdb.SearchTVShows, e
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetEposideDetail(id, seasonNumber, eposideNumber int, language string) (*tmdb.TVEpisodeDetails, error) {
|
||||
d, err := c.tmdbClient.GetTVEpisodeDetails(id, seasonNumber, eposideNumber, withLangOption(language))
|
||||
return d, err
|
||||
}
|
||||
|
||||
func wrapLanguage(lang string) string {
|
||||
if lang == "" {
|
||||
lang = "zh-CN"
|
||||
|
||||
28
pkg/transmission/transmission.go
Normal file
28
pkg/transmission/transmission.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package transmission
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"github.com/hekmon/transmissionrpc"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func NewClient(url1, user, password string) (*Client, error) {
|
||||
u, err := url.Parse(url1)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "parse url")
|
||||
}
|
||||
tbt, err := transmissionrpc.New(u.Hostname(), user, password, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "connect transmission")
|
||||
}
|
||||
return &Client{c: tbt}, nil
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
c *transmissionrpc.Client
|
||||
}
|
||||
|
||||
func (c *Client) Download(magnet string) (*transmissionrpc.Torrent, error) {
|
||||
t, err := c.c.TorrentAdd(&transmissionrpc.TorrentAddPayload{Filename: &magnet})
|
||||
return t, err
|
||||
}
|
||||
Reference in New Issue
Block a user