-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgid.go
184 lines (163 loc) · 7.32 KB
/
gid.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package arigo
// GID provides an object oriented approach to arigo.
// Instead of calling the methods on the client directly,
// you can call them on the GID instance.
type GID struct {
client *Client
GID string // gid of the download
}
func (gid *GID) String() string {
return gid.GID
}
// Subscribe subscribes to the given event but only dispatches events concerning
// this GID.
func (gid *GID) Subscribe(evtType EventType, listener EventListener) UnsubscribeFunc {
return gid.client.Subscribe(evtType, func(event *DownloadEvent) {
if event.GID == gid.GID {
listener(event)
}
})
}
// Delete removes the download from disk as well as from aria2.
func (gid *GID) Delete() error {
return gid.client.Delete(gid.GID)
}
// WaitForDownload waits for the download to finish.
func (gid *GID) WaitForDownload() error {
return gid.client.WaitForDownload(gid.GID)
}
// Remove removes the download.
// If the specified download is in progress, it is first stopped.
// The status of the removed download becomes removed.
func (gid *GID) Remove() error {
return gid.client.Remove(gid.GID)
}
// ForceRemove removes the download.
// This method behaves just like Remove() except that this method removes the download
// without performing any actions which take time, such as contacting BitTorrent trackers to
// unregister the download first.
func (gid *GID) ForceRemove() error {
return gid.client.ForceRemove(gid.GID)
}
// Pause pauses the download.
// The status of paused download becomes paused. If the download was active,
// the download is placed in the front of the queue. While the status is paused,
// the download is not started. To change status to waiting, use the Unpause() method.
func (gid *GID) Pause() error {
return gid.client.Pause(gid.GID)
}
// ForcePause pauses the download.
// This method behaves just like Pause() except that this method pauses downloads
// without performing any actions which take time, such as contacting BitTorrent trackers to
// unregister the download first.
func (gid *GID) ForcePause() error {
return gid.client.ForcePause(gid.GID)
}
// Unpause changes the status of the download from paused to waiting,
// making the download eligible to be restarted.
func (gid *GID) Unpause() error {
return gid.client.Unpause(gid.GID)
}
// TellStatus returns the progress of the download.
// If specified, the response only contains only the keys passed to the method.
// If keys is empty, the response contains all keys.
// This is useful when you just want specific keys and avoid unnecessary transfers.
func (gid *GID) TellStatus(keys ...string) (Status, error) {
return gid.client.TellStatus(gid.GID, keys...)
}
// GetURIs returns the URIs used in the download.
// The response is a slice of URI.
func (gid *GID) GetURIs() ([]URI, error) {
return gid.client.GetURIs(gid.GID)
}
// GetFiles returns the file list of the download.
// The response is a slice of File.
func (gid *GID) GetFiles() ([]File, error) {
return gid.client.GetFiles(gid.GID)
}
// GetPeers returns a list of peers of the download denoted by gid.
// This method is for BitTorrent only.
// The response is a slice of Peers.
func (gid *GID) GetPeers() ([]Peer, error) {
return gid.client.GetPeers(gid.GID)
}
// GetServers returns currently connected HTTP(S)/FTP/SFTP servers of the download denoted by gid.
// Returns a slice of FileServers.
func (gid *GID) GetServers() ([]FileServers, error) {
return gid.client.GetServers(gid.GID)
}
// ChangePosition changes the position of the download denoted by gid in the queue.
//
// If how is SetPositionStart, it moves the download to a position relative to the beginning of the queue.
// If how is SetPositionRelative, it moves the download to a position relative to the current position.
// If how is SetPositionEnd, it moves the download to a position relative to the end of the queue.
// If the destination position is less than 0 or beyond the end of the queue,
// it moves the download to the beginning or the end of the queue respectively.
//
// The response is an integer denoting the resulting position.
func (gid *GID) ChangePosition(pos int, how PositionSetBehaviour) (int, error) {
return gid.client.ChangePosition(gid.GID, pos, how)
}
// ChangeURIAt removes the URIs in delUris from and appends the URIs in addUris to download denoted by gid.
// A download can contain multiple files and URIs are attached to each file.
// fileIndex is used to select which file to remove/attach given URIs. fileIndex is 1-based.
// position is used to specify where URIs are inserted in the existing waiting URI list. position is 0-based.
// When position is nil, URIs are appended to the back of the list.
//
// This method first executes the removal and then the addition.
// position is the position after URIs are removed, not the position when this method is called.
// When removing an URI, if the same URIs exist in download, only one of them is removed for each URI in delUris.
//
// Returns two integers.
// The first integer is the number of URIs deleted.
// The second integer is the number of URIs added.
func (gid *GID) ChangeURIAt(fileIndex uint, delURIs []string, addURIs []string, position uint) (uint, uint, error) {
return gid.client.ChangeURIAt(gid.GID, fileIndex, delURIs, addURIs, position)
}
// ChangeURI removes the URIs in delUris from and appends the URIs in addUris to download denoted by gid.
// A download can contain multiple files and URIs are attached to each file.
// fileIndex is used to select which file to remove/attach given URIs. fileIndex is 1-based.
// position is used to specify where URIs are inserted in the existing waiting URI list. position is 0-based.
// URIs are appended to the back of the list.
//
// This method first executes the removal and then the addition.
// position is the position after URIs are removed, not the position when this method is called.
// When removing an URI, if the same URIs exist in download, only one of them is removed for each URI in delUris.
//
// Returns two integers.
// The first integer is the number of URIs deleted.
// The second integer is the number of URIs added.
func (gid *GID) ChangeURI(fileIndex uint, delURIs []string, addURIs []string) (uint, uint, error) {
return gid.client.ChangeURI(gid.GID, fileIndex, delURIs, addURIs)
}
// GetOptions returns Options of the download denoted by gid.
// Note that this method does not return options which have no default value and have not been set on the command-line,
// in configuration files or RPC methods.
func (gid *GID) GetOptions() (Options, error) {
return gid.client.GetOptions(gid.GID)
}
// ChangeOptions changes options of the download denoted by gid dynamically.
//
// Except for following options, all options are available:
// - DryRun
// - MetalinkBaseURI
// - ParameterizedURI
// - Pause
// - PieceLength
// - RPCSaveUploadMetadata
//
// Except for the following options, changing the other options of active download makes it restart
// (restart itself is managed by aria2, and no user intervention is required):
// - BtMaxPeers
// - BtRequestPeerSpeedLimit
// - BtRemoveUnselectedFile
// - ForceSave
// - MaxDownloadLimit
// - MaxUploadLimit
func (gid *GID) ChangeOptions(changes Options) error {
return gid.client.ChangeOptions(gid.GID, changes)
}
// RemoveDownloadResult removes a completed/error/removed download denoted by gid from memory.
func (gid *GID) RemoveDownloadResult() error {
return gid.client.RemoveDownloadResult(gid.GID)
}