-
Notifications
You must be signed in to change notification settings - Fork 28
/
torrent_action_requests.go
153 lines (133 loc) · 6.26 KB
/
torrent_action_requests.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package transmissionrpc
import (
"context"
"fmt"
)
/*
Torrent Action Requests
https://github.com/transmission/transmission/blob/4.0.3/docs/rpc-spec.md#31-torrent-action-requests
*/
type torrentActionIDsParam struct {
IDs []int64 `json:"ids,omitempty"`
}
type torrentActionHashesParam struct {
IDs []string `json:"ids,omitempty"`
}
type torrentActionRecentlyActiveParam struct {
IDs string `json:"ids"`
}
// TorrentStartIDs starts torrent(s) which id is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentStartIDs(ctx context.Context, ids []int64) (err error) {
if err = c.rpcCall(ctx, "torrent-start", &torrentActionIDsParam{IDs: ids}, nil); err != nil {
err = fmt.Errorf("'torrent-start' rpc method failed: %w", err)
}
return
}
// TorrentStartHashes starts torrent(s) which hash is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentStartHashes(ctx context.Context, hashes []string) (err error) {
if err = c.rpcCall(ctx, "torrent-start", &torrentActionHashesParam{IDs: hashes}, nil); err != nil {
err = fmt.Errorf("'torrent-start' rpc method failed: %w", err)
}
return
}
// TorrentStartRecentlyActive starts torrent(s) which have been recently active.
func (c *Client) TorrentStartRecentlyActive(ctx context.Context) (err error) {
if err = c.rpcCall(ctx, "torrent-start", &torrentActionRecentlyActiveParam{IDs: "recently-active"}, nil); err != nil {
err = fmt.Errorf("'torrent-start' rpc method failed: %w", err)
}
return
}
// TorrentStartNowIDs starts (now) torrent(s) which id is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentStartNowIDs(ctx context.Context, ids []int64) (err error) {
if err = c.rpcCall(ctx, "torrent-start-now", &torrentActionIDsParam{IDs: ids}, nil); err != nil {
err = fmt.Errorf("'torrent-start-now' rpc method failed: %w", err)
}
return
}
// TorrentStartNowHashes starts (now) torrent(s) which hash is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentStartNowHashes(ctx context.Context, hashes []string) (err error) {
if err = c.rpcCall(ctx, "torrent-start-now", &torrentActionHashesParam{IDs: hashes}, nil); err != nil {
err = fmt.Errorf("'torrent-start-now' rpc method failed: %w", err)
}
return
}
// TorrentStartNowRecentlyActive starts (now) torrent(s) which have been recently active.
func (c *Client) TorrentStartNowRecentlyActive(ctx context.Context) (err error) {
if err = c.rpcCall(ctx, "torrent-start-now", &torrentActionRecentlyActiveParam{IDs: "recently-active"}, nil); err != nil {
err = fmt.Errorf("'torrent-start-now' rpc method failed: %w", err)
}
return
}
// TorrentStopIDs stops torrent(s) which id is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentStopIDs(ctx context.Context, ids []int64) (err error) {
if err = c.rpcCall(ctx, "torrent-stop", &torrentActionIDsParam{IDs: ids}, nil); err != nil {
err = fmt.Errorf("'torrent-stop' rpc method failed: %w", err)
}
return
}
// TorrentStopHashes stops torrent(s) which hash is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentStopHashes(ctx context.Context, hashes []string) (err error) {
if err = c.rpcCall(ctx, "torrent-stop", &torrentActionHashesParam{IDs: hashes}, nil); err != nil {
err = fmt.Errorf("'torrent-stop' rpc method failed: %w", err)
}
return
}
// TorrentStopRecentlyActive stops torrent(s) which have been recently active.
func (c *Client) TorrentStopRecentlyActive(ctx context.Context) (err error) {
if err = c.rpcCall(ctx, "torrent-stop", &torrentActionRecentlyActiveParam{IDs: "recently-active"}, nil); err != nil {
err = fmt.Errorf("'torrent-stop' rpc method failed: %w", err)
}
return
}
// TorrentVerifyIDs verifys torrent(s) which id is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentVerifyIDs(ctx context.Context, ids []int64) (err error) {
if err = c.rpcCall(ctx, "torrent-verify", &torrentActionIDsParam{IDs: ids}, nil); err != nil {
err = fmt.Errorf("'torrent-verify' rpc method failed: %w", err)
}
return
}
// TorrentVerifyHashes verifys torrent(s) which hash is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentVerifyHashes(ctx context.Context, hashes []string) (err error) {
if err = c.rpcCall(ctx, "torrent-verify", &torrentActionHashesParam{IDs: hashes}, nil); err != nil {
err = fmt.Errorf("'torrent-verify' rpc method failed: %w", err)
}
return
}
// TorrentVerifyRecentlyActive verifys torrent(s) which have been recently active.
func (c *Client) TorrentVerifyRecentlyActive(ctx context.Context) (err error) {
if err = c.rpcCall(ctx, "torrent-verify", &torrentActionRecentlyActiveParam{IDs: "recently-active"}, nil); err != nil {
err = fmt.Errorf("'torrent-verify' rpc method failed: %w", err)
}
return
}
// TorrentReannounceIDs reannounces torrent(s) which id is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentReannounceIDs(ctx context.Context, ids []int64) (err error) {
if err = c.rpcCall(ctx, "torrent-reannounce", &torrentActionIDsParam{IDs: ids}, nil); err != nil {
err = fmt.Errorf("'torrent-reannounce' rpc method failed: %w", err)
}
return
}
// TorrentReannounceHashes reannounces torrent(s) which hash is in the provided slice.
// Can be one, can be several, can be all (if slice is empty or nil).
func (c *Client) TorrentReannounceHashes(ctx context.Context, hashes []string) (err error) {
if err = c.rpcCall(ctx, "torrent-reannounce", &torrentActionHashesParam{IDs: hashes}, nil); err != nil {
err = fmt.Errorf("'torrent-reannounce' rpc method failed: %w", err)
}
return
}
// TorrentReannounceRecentlyActive reannounces torrent(s) which have been recently active.
func (c *Client) TorrentReannounceRecentlyActive(ctx context.Context) (err error) {
if err = c.rpcCall(ctx, "torrent-reannounce", &torrentActionRecentlyActiveParam{IDs: "recently-active"}, nil); err != nil {
err = fmt.Errorf("'torrent-reannounce' rpc method failed: %w", err)
}
return
}