Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/pkg/aria2/rpc/client.go
1562 views
1
package rpc
2
3
import (
4
"context"
5
"encoding/base64"
6
"errors"
7
"net/url"
8
"os"
9
"time"
10
)
11
12
// Option is a container for specifying Call parameters and returning results
13
type Option map[string]interface{}
14
15
type Client interface {
16
Protocol
17
Close() error
18
}
19
20
type client struct {
21
caller
22
url *url.URL
23
token string
24
}
25
26
var (
27
errInvalidParameter = errors.New("invalid parameter")
28
errNotImplemented = errors.New("not implemented")
29
errConnTimeout = errors.New("connect to aria2 daemon timeout")
30
)
31
32
// New returns an instance of Client
33
func New(ctx context.Context, uri string, token string, timeout time.Duration, notifier Notifier) (Client, error) {
34
u, err := url.Parse(uri)
35
if err != nil {
36
return nil, err
37
}
38
var caller caller
39
switch u.Scheme {
40
case "http", "https":
41
caller = newHTTPCaller(ctx, u, timeout, notifier)
42
case "ws", "wss":
43
caller, err = newWebsocketCaller(ctx, u.String(), timeout, notifier)
44
if err != nil {
45
return nil, err
46
}
47
default:
48
return nil, errInvalidParameter
49
}
50
c := &client{caller: caller, url: u, token: token}
51
return c, nil
52
}
53
54
// `aria2.addUri([secret, ]uris[, options[, position]])`
55
// This method adds a new download. uris is an array of HTTP/FTP/SFTP/BitTorrent URIs (strings) pointing to the same resource.
56
// If you mix URIs pointing to different resources, then the download may fail or be corrupted without aria2 complaining.
57
// When adding BitTorrent Magnet URIs, uris must have only one element and it should be BitTorrent Magnet URI.
58
// options is a struct and its members are pairs of option name and value.
59
// If position is given, it must be an integer starting from 0.
60
// The new download will be inserted at position in the waiting queue.
61
// If position is omitted or position is larger than the current size of the queue, the new download is appended to the end of the queue.
62
// This method returns the GID of the newly registered download.
63
func (c *client) AddURI(uris []string, options ...interface{}) (gid string, err error) {
64
params := make([]interface{}, 0, 2)
65
if c.token != "" {
66
params = append(params, "token:"+c.token)
67
}
68
params = append(params, uris)
69
if options != nil {
70
params = append(params, options...)
71
}
72
err = c.Call(aria2AddURI, params, &gid)
73
return
74
}
75
76
// `aria2.addTorrent([secret, ]torrent[, uris[, options[, position]]])`
77
// This method adds a BitTorrent download by uploading a ".torrent" file.
78
// If you want to add a BitTorrent Magnet URI, use the aria2.addUri() method instead.
79
// torrent must be a base64-encoded string containing the contents of the ".torrent" file.
80
// uris is an array of URIs (string). uris is used for Web-seeding.
81
// For single file torrents, the URI can be a complete URI pointing to the resource; if URI ends with /, name in torrent file is added.
82
// For multi-file torrents, name and path in torrent are added to form a URI for each file. options is a struct and its members are pairs of option name and value.
83
// If position is given, it must be an integer starting from 0.
84
// The new download will be inserted at position in the waiting queue.
85
// If position is omitted or position is larger than the current size of the queue, the new download is appended to the end of the queue.
86
// This method returns the GID of the newly registered download.
87
// If --rpc-save-upload-metadata is true, the uploaded data is saved as a file named as the hex string of SHA-1 hash of data plus ".torrent" in the directory specified by --dir option.
88
// E.g. a file name might be 0a3893293e27ac0490424c06de4d09242215f0a6.torrent.
89
// If a file with the same name already exists, it is overwritten!
90
// If the file cannot be saved successfully or --rpc-save-upload-metadata is false, the downloads added by this method are not saved by --save-session.
91
func (c *client) AddTorrent(filename string, options ...interface{}) (gid string, err error) {
92
co, err := os.ReadFile(filename)
93
if err != nil {
94
return
95
}
96
file := base64.StdEncoding.EncodeToString(co)
97
params := make([]interface{}, 0, 3)
98
if c.token != "" {
99
params = append(params, "token:"+c.token)
100
}
101
params = append(params, file)
102
params = append(params, []interface{}{})
103
if options != nil {
104
params = append(params, options...)
105
}
106
err = c.Call(aria2AddTorrent, params, &gid)
107
return
108
}
109
110
// `aria2.addMetalink([secret, ]metalink[, options[, position]])`
111
// This method adds a Metalink download by uploading a ".metalink" file.
112
// metalink is a base64-encoded string which contains the contents of the ".metalink" file.
113
// options is a struct and its members are pairs of option name and value.
114
// If position is given, it must be an integer starting from 0.
115
// The new download will be inserted at position in the waiting queue.
116
// If position is omitted or position is larger than the current size of the queue, the new download is appended to the end of the queue.
117
// This method returns an array of GIDs of newly registered downloads.
118
// If --rpc-save-upload-metadata is true, the uploaded data is saved as a file named hex string of SHA-1 hash of data plus ".metalink" in the directory specified by --dir option.
119
// E.g. a file name might be 0a3893293e27ac0490424c06de4d09242215f0a6.metalink.
120
// If a file with the same name already exists, it is overwritten!
121
// If the file cannot be saved successfully or --rpc-save-upload-metadata is false, the downloads added by this method are not saved by --save-session.
122
func (c *client) AddMetalink(filename string, options ...interface{}) (gid []string, err error) {
123
co, err := os.ReadFile(filename)
124
if err != nil {
125
return
126
}
127
file := base64.StdEncoding.EncodeToString(co)
128
params := make([]interface{}, 0, 2)
129
if c.token != "" {
130
params = append(params, "token:"+c.token)
131
}
132
params = append(params, file)
133
if options != nil {
134
params = append(params, options...)
135
}
136
err = c.Call(aria2AddMetalink, params, &gid)
137
return
138
}
139
140
// `aria2.remove([secret, ]gid)`
141
// This method removes the download denoted by gid (string).
142
// If the specified download is in progress, it is first stopped.
143
// The status of the removed download becomes removed.
144
// This method returns GID of removed download.
145
func (c *client) Remove(gid string) (g string, err error) {
146
params := make([]interface{}, 0, 2)
147
if c.token != "" {
148
params = append(params, "token:"+c.token)
149
}
150
params = append(params, gid)
151
err = c.Call(aria2Remove, params, &g)
152
return
153
}
154
155
// `aria2.forceRemove([secret, ]gid)`
156
// This method removes the download denoted by gid.
157
// This method behaves just like aria2.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.
158
func (c *client) ForceRemove(gid string) (g string, err error) {
159
params := make([]interface{}, 0, 2)
160
if c.token != "" {
161
params = append(params, "token:"+c.token)
162
}
163
params = append(params, gid)
164
err = c.Call(aria2ForceRemove, params, &g)
165
return
166
}
167
168
// `aria2.pause([secret, ]gid)`
169
// This method pauses the download denoted by gid (string).
170
// The status of paused download becomes paused.
171
// If the download was active, the download is placed in the front of waiting queue.
172
// While the status is paused, the download is not started.
173
// To change status to waiting, use the aria2.unpause() method.
174
// This method returns GID of paused download.
175
func (c *client) Pause(gid string) (g string, err error) {
176
params := make([]interface{}, 0, 2)
177
if c.token != "" {
178
params = append(params, "token:"+c.token)
179
}
180
params = append(params, gid)
181
err = c.Call(aria2Pause, params, &g)
182
return
183
}
184
185
// `aria2.pauseAll([secret])`
186
// This method is equal to calling aria2.pause() for every active/waiting download.
187
// This methods returns OK.
188
func (c *client) PauseAll() (ok string, err error) {
189
params := []string{}
190
if c.token != "" {
191
params = append(params, "token:"+c.token)
192
}
193
err = c.Call(aria2PauseAll, params, &ok)
194
return
195
}
196
197
// `aria2.forcePause([secret, ]gid)`
198
// This method pauses the download denoted by gid.
199
// This method behaves just like aria2.pause() except that this method pauses downloads without performing any actions which take time, such as contacting BitTorrent trackers to unregister the download first.
200
func (c *client) ForcePause(gid string) (g string, err error) {
201
params := make([]interface{}, 0, 2)
202
if c.token != "" {
203
params = append(params, "token:"+c.token)
204
}
205
params = append(params, gid)
206
err = c.Call(aria2ForcePause, params, &g)
207
return
208
}
209
210
// `aria2.forcePauseAll([secret])`
211
// This method is equal to calling aria2.forcePause() for every active/waiting download.
212
// This methods returns OK.
213
func (c *client) ForcePauseAll() (ok string, err error) {
214
params := []string{}
215
if c.token != "" {
216
params = append(params, "token:"+c.token)
217
}
218
err = c.Call(aria2ForcePauseAll, params, &ok)
219
return
220
}
221
222
// `aria2.unpause([secret, ]gid)`
223
// This method changes the status of the download denoted by gid (string) from paused to waiting, making the download eligible to be restarted.
224
// This method returns the GID of the unpaused download.
225
func (c *client) Unpause(gid string) (g string, err error) {
226
params := make([]interface{}, 0, 2)
227
if c.token != "" {
228
params = append(params, "token:"+c.token)
229
}
230
params = append(params, gid)
231
err = c.Call(aria2Unpause, params, &g)
232
return
233
}
234
235
// `aria2.unpauseAll([secret])`
236
// This method is equal to calling aria2.unpause() for every active/waiting download.
237
// This methods returns OK.
238
func (c *client) UnpauseAll() (ok string, err error) {
239
params := []string{}
240
if c.token != "" {
241
params = append(params, "token:"+c.token)
242
}
243
err = c.Call(aria2UnpauseAll, params, &ok)
244
return
245
}
246
247
// `aria2.tellStatus([secret, ]gid[, keys])`
248
// This method returns the progress of the download denoted by gid (string).
249
// keys is an array of strings.
250
// If specified, the response contains only keys in the keys array.
251
// If keys is empty or omitted, the response contains all keys.
252
// This is useful when you just want specific keys and avoid unnecessary transfers.
253
// For example, aria2.tellStatus("2089b05ecca3d829", ["gid", "status"]) returns the gid and status keys only.
254
// The response is a struct and contains following keys. Values are strings.
255
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.tellStatus
256
func (c *client) TellStatus(gid string, keys ...string) (info StatusInfo, err error) {
257
params := make([]interface{}, 0, 2)
258
if c.token != "" {
259
params = append(params, "token:"+c.token)
260
}
261
params = append(params, gid)
262
if keys != nil {
263
params = append(params, keys)
264
}
265
err = c.Call(aria2TellStatus, params, &info)
266
return
267
}
268
269
// `aria2.getUris([secret, ]gid)`
270
// This method returns the URIs used in the download denoted by gid (string).
271
// The response is an array of structs and it contains following keys. Values are string.
272
//
273
// uri URI
274
// status 'used' if the URI is in use. 'waiting' if the URI is still waiting in the queue.
275
func (c *client) GetURIs(gid string) (infos []URIInfo, err error) {
276
params := make([]interface{}, 0, 2)
277
if c.token != "" {
278
params = append(params, "token:"+c.token)
279
}
280
params = append(params, gid)
281
err = c.Call(aria2GetURIs, params, &infos)
282
return
283
}
284
285
// `aria2.getFiles([secret, ]gid)`
286
// This method returns the file list of the download denoted by gid (string).
287
// The response is an array of structs which contain following keys. Values are strings.
288
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getFiles
289
func (c *client) GetFiles(gid string) (infos []FileInfo, err error) {
290
params := make([]interface{}, 0, 2)
291
if c.token != "" {
292
params = append(params, "token:"+c.token)
293
}
294
params = append(params, gid)
295
err = c.Call(aria2GetFiles, params, &infos)
296
return
297
}
298
299
// `aria2.getPeers([secret, ]gid)`
300
// This method returns a list peers of the download denoted by gid (string).
301
// This method is for BitTorrent only.
302
// The response is an array of structs and contains the following keys. Values are strings.
303
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getPeers
304
func (c *client) GetPeers(gid string) (infos []PeerInfo, err error) {
305
params := make([]interface{}, 0, 2)
306
if c.token != "" {
307
params = append(params, "token:"+c.token)
308
}
309
params = append(params, gid)
310
err = c.Call(aria2GetPeers, params, &infos)
311
return
312
}
313
314
// `aria2.getServers([secret, ]gid)`
315
// This method returns currently connected HTTP(S)/FTP/SFTP servers of the download denoted by gid (string).
316
// The response is an array of structs and contains the following keys. Values are strings.
317
// https://aria2.github.io/manual/en/html/aria2c.html#aria2.getServers
318
func (c *client) GetServers(gid string) (infos []ServerInfo, err error) {
319
params := make([]interface{}, 0, 2)
320
if c.token != "" {
321
params = append(params, "token:"+c.token)
322
}
323
params = append(params, gid)
324
err = c.Call(aria2GetServers, params, &infos)
325
return
326
}
327
328
// `aria2.tellActive([secret][, keys])`
329
// This method returns a list of active downloads.
330
// The response is an array of the same structs as returned by the aria2.tellStatus() method.
331
// For the keys parameter, please refer to the aria2.tellStatus() method.
332
func (c *client) TellActive(keys ...string) (infos []StatusInfo, err error) {
333
params := make([]interface{}, 0, 1)
334
if c.token != "" {
335
params = append(params, "token:"+c.token)
336
}
337
if keys != nil {
338
params = append(params, keys)
339
}
340
err = c.Call(aria2TellActive, params, &infos)
341
return
342
}
343
344
// `aria2.tellWaiting([secret, ]offset, num[, keys])`
345
// This method returns a list of waiting downloads, including paused ones.
346
// offset is an integer and specifies the offset from the download waiting at the front.
347
// num is an integer and specifies the max. number of downloads to be returned.
348
// For the keys parameter, please refer to the aria2.tellStatus() method.
349
// If offset is a positive integer, this method returns downloads in the range of [offset, offset + num).
350
// offset can be a negative integer. offset == -1 points last download in the waiting queue and offset == -2 points the download before the last download, and so on.
351
// Downloads in the response are in reversed order then.
352
// For example, imagine three downloads "A","B" and "C" are waiting in this order.
353
// aria2.tellWaiting(0, 1) returns ["A"].
354
// aria2.tellWaiting(1, 2) returns ["B", "C"].
355
// aria2.tellWaiting(-1, 2) returns ["C", "B"].
356
// The response is an array of the same structs as returned by aria2.tellStatus() method.
357
func (c *client) TellWaiting(offset, num int, keys ...string) (infos []StatusInfo, err error) {
358
params := make([]interface{}, 0, 3)
359
if c.token != "" {
360
params = append(params, "token:"+c.token)
361
}
362
params = append(params, offset)
363
params = append(params, num)
364
if keys != nil {
365
params = append(params, keys)
366
}
367
err = c.Call(aria2TellWaiting, params, &infos)
368
return
369
}
370
371
// `aria2.tellStopped([secret, ]offset, num[, keys])`
372
// This method returns a list of stopped downloads.
373
// offset is an integer and specifies the offset from the least recently stopped download.
374
// num is an integer and specifies the max. number of downloads to be returned.
375
// For the keys parameter, please refer to the aria2.tellStatus() method.
376
// offset and num have the same semantics as described in the aria2.tellWaiting() method.
377
// The response is an array of the same structs as returned by the aria2.tellStatus() method.
378
func (c *client) TellStopped(offset, num int, keys ...string) (infos []StatusInfo, err error) {
379
params := make([]interface{}, 0, 3)
380
if c.token != "" {
381
params = append(params, "token:"+c.token)
382
}
383
params = append(params, offset)
384
params = append(params, num)
385
if keys != nil {
386
params = append(params, keys)
387
}
388
err = c.Call(aria2TellStopped, params, &infos)
389
return
390
}
391
392
// `aria2.changePosition([secret, ]gid, pos, how)`
393
// This method changes the position of the download denoted by gid in the queue.
394
// pos is an integer. how is a string.
395
// If how is POS_SET, it moves the download to a position relative to the beginning of the queue.
396
// If how is POS_CUR, it moves the download to a position relative to the current position.
397
// If how is POS_END, it moves the download to a position relative to the end of the queue.
398
// 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.
399
// The response is an integer denoting the resulting position.
400
// For example, if GID#2089b05ecca3d829 is currently in position 3, aria2.changePosition('2089b05ecca3d829', -1, 'POS_CUR') will change its position to 2. Additionally aria2.changePosition('2089b05ecca3d829', 0, 'POS_SET') will change its position to 0 (the beginning of the queue).
401
func (c *client) ChangePosition(gid string, pos int, how string) (p int, err error) {
402
params := make([]interface{}, 0, 3)
403
if c.token != "" {
404
params = append(params, "token:"+c.token)
405
}
406
params = append(params, gid)
407
params = append(params, pos)
408
params = append(params, how)
409
err = c.Call(aria2ChangePosition, params, &p)
410
return
411
}
412
413
// `aria2.changeUri([secret, ]gid, fileIndex, delUris, addUris[, position])`
414
// This method removes the URIs in delUris from and appends the URIs in addUris to download denoted by gid.
415
// delUris and addUris are lists of strings.
416
// A download can contain multiple files and URIs are attached to each file.
417
// fileIndex is used to select which file to remove/attach given URIs. fileIndex is 1-based.
418
// position is used to specify where URIs are inserted in the existing waiting URI list. position is 0-based.
419
// When position is omitted, URIs are appended to the back of the list.
420
// This method first executes the removal and then the addition.
421
// position is the position after URIs are removed, not the position when this method is called.
422
// When removing an URI, if the same URIs exist in download, only one of them is removed for each URI in delUris.
423
// In other words, if there are three URIs http://example.org/aria2 and you want remove them all, you have to specify (at least) 3 http://example.org/aria2 in delUris.
424
// This method returns a list which contains two integers.
425
// The first integer is the number of URIs deleted.
426
// The second integer is the number of URIs added.
427
func (c *client) ChangeURI(gid string, fileindex int, delUris []string, addUris []string, position ...int) (p []int, err error) {
428
params := make([]interface{}, 0, 5)
429
if c.token != "" {
430
params = append(params, "token:"+c.token)
431
}
432
params = append(params, gid)
433
params = append(params, fileindex)
434
params = append(params, delUris)
435
params = append(params, addUris)
436
if position != nil {
437
params = append(params, position[0])
438
}
439
err = c.Call(aria2ChangeURI, params, &p)
440
return
441
}
442
443
// `aria2.getOption([secret, ]gid)`
444
// This method returns options of the download denoted by gid.
445
// The response is a struct where keys are the names of options.
446
// The values are strings.
447
// 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.
448
func (c *client) GetOption(gid string) (m Option, err error) {
449
params := make([]interface{}, 0, 2)
450
if c.token != "" {
451
params = append(params, "token:"+c.token)
452
}
453
params = append(params, gid)
454
err = c.Call(aria2GetOption, params, &m)
455
return
456
}
457
458
// `aria2.changeOption([secret, ]gid, options)`
459
// This method changes options of the download denoted by gid (string) dynamically. options is a struct.
460
// The following options are available for active downloads:
461
//
462
// bt-max-peers
463
// bt-request-peer-speed-limit
464
// bt-remove-unselected-file
465
// force-save
466
// max-download-limit
467
// max-upload-limit
468
//
469
// For waiting or paused downloads, in addition to the above options, options listed in Input File subsection are available, except for following options: dry-run, metalink-base-uri, parameterized-uri, pause, piece-length and rpc-save-upload-metadata option.
470
// This method returns OK for success.
471
func (c *client) ChangeOption(gid string, option Option) (ok string, err error) {
472
params := make([]interface{}, 0, 2)
473
if c.token != "" {
474
params = append(params, "token:"+c.token)
475
}
476
params = append(params, gid)
477
if option != nil {
478
params = append(params, option)
479
}
480
err = c.Call(aria2ChangeOption, params, &ok)
481
return
482
}
483
484
// `aria2.getGlobalOption([secret])`
485
// This method returns the global options.
486
// The response is a struct.
487
// Its keys are the names of options.
488
// Values are strings.
489
// 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. Because global options are used as a template for the options of newly added downloads, the response contains keys returned by the aria2.getOption() method.
490
func (c *client) GetGlobalOption() (m Option, err error) {
491
params := []string{}
492
if c.token != "" {
493
params = append(params, "token:"+c.token)
494
}
495
err = c.Call(aria2GetGlobalOption, params, &m)
496
return
497
}
498
499
// `aria2.changeGlobalOption([secret, ]options)`
500
// This method changes global options dynamically.
501
// options is a struct.
502
// The following options are available:
503
//
504
// bt-max-open-files
505
// download-result
506
// log
507
// log-level
508
// max-concurrent-downloads
509
// max-download-result
510
// max-overall-download-limit
511
// max-overall-upload-limit
512
// save-cookies
513
// save-session
514
// server-stat-of
515
//
516
// In addition, options listed in the Input File subsection are available, except for following options: checksum, index-out, out, pause and select-file.
517
// With the log option, you can dynamically start logging or change log file.
518
// To stop logging, specify an empty string("") as the parameter value.
519
// Note that log file is always opened in append mode.
520
// This method returns OK for success.
521
func (c *client) ChangeGlobalOption(options Option) (ok string, err error) {
522
params := make([]interface{}, 0, 2)
523
if c.token != "" {
524
params = append(params, "token:"+c.token)
525
}
526
params = append(params, options)
527
err = c.Call(aria2ChangeGlobalOption, params, &ok)
528
return
529
}
530
531
// `aria2.getGlobalStat([secret])`
532
// This method returns global statistics such as the overall download and upload speeds.
533
// The response is a struct and contains the following keys. Values are strings.
534
//
535
// downloadSpeed Overall download speed (byte/sec).
536
// uploadSpeed Overall upload speed(byte/sec).
537
// numActive The number of active downloads.
538
// numWaiting The number of waiting downloads.
539
// numStopped The number of stopped downloads in the current session.
540
// This value is capped by the --max-download-result option.
541
// numStoppedTotal The number of stopped downloads in the current session and not capped by the --max-download-result option.
542
func (c *client) GetGlobalStat() (info GlobalStatInfo, err error) {
543
params := []string{}
544
if c.token != "" {
545
params = append(params, "token:"+c.token)
546
}
547
err = c.Call(aria2GetGlobalStat, params, &info)
548
return
549
}
550
551
// `aria2.purgeDownloadResult([secret])`
552
// This method purges completed/error/removed downloads to free memory.
553
// This method returns OK.
554
func (c *client) PurgeDownloadResult() (ok string, err error) {
555
params := []string{}
556
if c.token != "" {
557
params = append(params, "token:"+c.token)
558
}
559
err = c.Call(aria2PurgeDownloadResult, params, &ok)
560
return
561
}
562
563
// `aria2.removeDownloadResult([secret, ]gid)`
564
// This method removes a completed/error/removed download denoted by gid from memory.
565
// This method returns OK for success.
566
func (c *client) RemoveDownloadResult(gid string) (ok string, err error) {
567
params := make([]interface{}, 0, 2)
568
if c.token != "" {
569
params = append(params, "token:"+c.token)
570
}
571
params = append(params, gid)
572
err = c.Call(aria2RemoveDownloadResult, params, &ok)
573
return
574
}
575
576
// `aria2.getVersion([secret])`
577
// This method returns the version of aria2 and the list of enabled features.
578
// The response is a struct and contains following keys.
579
//
580
// version Version number of aria2 as a string.
581
// enabledFeatures List of enabled features. Each feature is given as a string.
582
func (c *client) GetVersion() (info VersionInfo, err error) {
583
params := []string{}
584
if c.token != "" {
585
params = append(params, "token:"+c.token)
586
}
587
err = c.Call(aria2GetVersion, params, &info)
588
return
589
}
590
591
// `aria2.getSessionInfo([secret])`
592
// This method returns session information.
593
// The response is a struct and contains following key.
594
//
595
// sessionId Session ID, which is generated each time when aria2 is invoked.
596
func (c *client) GetSessionInfo() (info SessionInfo, err error) {
597
params := []string{}
598
if c.token != "" {
599
params = append(params, "token:"+c.token)
600
}
601
err = c.Call(aria2GetSessionInfo, params, &info)
602
return
603
}
604
605
// `aria2.shutdown([secret])`
606
// This method shutdowns aria2.
607
// This method returns OK.
608
func (c *client) Shutdown() (ok string, err error) {
609
params := []string{}
610
if c.token != "" {
611
params = append(params, "token:"+c.token)
612
}
613
err = c.Call(aria2Shutdown, params, &ok)
614
return
615
}
616
617
// `aria2.forceShutdown([secret])`
618
// This method shuts down aria2().
619
// This method behaves like :func:'aria2.shutdown` without performing any actions which take time, such as contacting BitTorrent trackers to unregister downloads first.
620
// This method returns OK.
621
func (c *client) ForceShutdown() (ok string, err error) {
622
params := []string{}
623
if c.token != "" {
624
params = append(params, "token:"+c.token)
625
}
626
err = c.Call(aria2ForceShutdown, params, &ok)
627
return
628
}
629
630
// `aria2.saveSession([secret])`
631
// This method saves the current session to a file specified by the --save-session option.
632
// This method returns OK if it succeeds.
633
func (c *client) SaveSession() (ok string, err error) {
634
params := []string{}
635
if c.token != "" {
636
params = append(params, "token:"+c.token)
637
}
638
err = c.Call(aria2SaveSession, params, &ok)
639
return
640
}
641
642
// `system.multicall(methods)`
643
// This methods encapsulates multiple method calls in a single request.
644
// methods is an array of structs.
645
// The structs contain two keys: methodName and params.
646
// methodName is the method name to call and params is array containing parameters to the method call.
647
// This method returns an array of responses.
648
// The elements will be either a one-item array containing the return value of the method call or a struct of fault element if an encapsulated method call fails.
649
func (c *client) Multicall(methods []Method) (r []interface{}, err error) {
650
if len(methods) == 0 {
651
err = errInvalidParameter
652
return
653
}
654
err = c.Call(aria2Multicall, []interface{}{methods}, &r)
655
return
656
}
657
658
// `system.listMethods()`
659
// This method returns the all available RPC methods in an array of string.
660
// Unlike other methods, this method does not require secret token.
661
// This is safe because this method just returns the available method names.
662
func (c *client) ListMethods() (methods []string, err error) {
663
err = c.Call(aria2ListMethods, []string{}, &methods)
664
return
665
}
666
667