-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathqbittorrent.go
51 lines (40 loc) · 922 Bytes
/
qbittorrent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package client
import (
"context"
"fmt"
"github.com/autobrr/go-qbittorrent"
)
type qBitClient struct {
commonClient
}
func (c qBitClient) download(ctx context.Context, content *content) error {
qb := qbittorrent.NewClient(qbittorrent.Config{
Host: fmt.Sprintf("http://%v:%v/", c.config.Qbittorrent.Host, c.config.Qbittorrent.Port),
Username: c.config.Qbittorrent.Username,
Password: c.config.Qbittorrent.Password,
Timeout: 1,
})
err := qb.LoginCtx(ctx)
if err != nil {
return err
}
pref, err := qb.GetAppPreferencesCtx(ctx)
if err != nil {
return err
}
for _, item := range *content {
category := c.downloadCategory(item.Content.Type)
err = qb.AddTorrentFromUrlCtx(
ctx,
item.Torrent.MagnetUri(),
map[string]string{
"savepath": fmt.Sprintf("%v/%v", pref.SavePath, category),
"category": category,
},
)
if err != nil {
return err
}
}
return nil
}