mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-29 22:18:08 +08:00
basic find download ability
This commit is contained in:
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