-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtorrent_set_location.go
51 lines (45 loc) · 1.83 KB
/
torrent_set_location.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 transmissionrpc
import (
"context"
"fmt"
)
/*
Moving a torrent
https://github.com/transmission/transmission/blob/4.0.3/docs/rpc-spec.md#36-moving-a-torrent
*/
// TorrentSetLocation allows to set a new location for one or more torrents.
// 'location' is the new torrent location.
// 'move' if true, move from previous location. Otherwise, search "location" for file.
func (c *Client) TorrentSetLocation(ctx context.Context, id int64, location string, move bool) (err error) {
if err = c.rpcCall(ctx, "torrent-set-location", torrentSetLocationPayload{
IDs: []int64{id},
Location: location,
Move: move,
}, nil); err != nil {
err = fmt.Errorf("'torrent-set-location' rpc method failed: %w", err)
}
return
}
// TorrentSetLocationHash allows to set a new location for one or more torrents.
// 'location' is the new torrent location.
// 'move' if true, move from previous location. Otherwise, search "location" for file.
func (c *Client) TorrentSetLocationHash(ctx context.Context, hash, location string, move bool) (err error) {
if err = c.rpcCall(ctx, "torrent-set-location", torrentSetLocationHashPayload{
Hashes: []string{hash},
Location: location,
Move: move,
}, nil); err != nil {
err = fmt.Errorf("'torrent-set-location' rpc method failed: %w", err)
}
return
}
type torrentSetLocationPayload struct {
IDs []int64 `json:"ids"` // torrent list
Location string `json:"location"` // the new torrent location
Move bool `json:"move"` // if true, move from previous location. Otherwise, search "location" for files
}
type torrentSetLocationHashPayload struct {
Hashes []string `json:"ids"` // torrent list
Location string `json:"location"` // the new torrent location
Move bool `json:"move"` // if true, move from previous location. Otherwise, search "location" for files
}