aria2 provides JSON-RPC over HTTP and XML-RPC over HTTP interfaces that offer basically the same functionality. aria2 also provides JSON-RPC over WebSocket. JSON-RPC over WebSocket uses the same method signatures and response format as JSON-RPC over HTTP, but additionally provides server-initiated notifications. See JSON-RPC over WebSocket section for more information.
The request path of the JSON-RPC interface (for both over HTTP and over
WebSocket) is /jsonrpc
. The request path of the XML-RPC interface is
/rpc
.
The WebSocket URI for JSON-RPC over WebSocket is
ws://HOST:PORT/jsonrpc
. If you enabled SSL/TLS encryption, use
wss://HOST:PORT/jsonrpc
instead.
The implemented JSON-RPC is based on JSON-RPC 2.0 <http://jsonrpc.org/specification>, and supports HTTP POST and GET (JSONP). The WebSocket transport is an aria2 extension.
The JSON-RPC interface does not support notifications over HTTP, but the RPC server will send notifications over WebSocket. It also does not support floating point numbers. The character encoding must be UTF-8.
When reading the following documentation for JSON-RPC, interpret structs as JSON objects.
GID
The GID (or gid) is a key to manage each download. Each download will be assigned a unique GID. The GID is stored as 64-bit binary value in aria2. For RPC access, it is represented as a hex string of 16 characters (e.g.,2089b05ecca3d829
). Normally, aria2 generates this GID for each download, but the user can specify GIDs manually using the--gid
option. When querying downloads by GID, you can specify only the prefix of a GID as long as it is unique among others.
All code examples are compatible with the Python 2.7 interpreter. For information on the secret parameter, see RPC authorization secret token.
aria2.
addUri
([secret, ]uris[,
options[, position]])This method adds a new download. uris is an array of HTTP/FTP/SFTP/BitTorrent URIs (strings) pointing to the same resource. If you mix URIs pointing to different resources, then the download may fail or be corrupted without aria2 complaining. When adding BitTorrent Magnet URIs, uris must have only one element and it should be BitTorrent Magnet URI. options is a struct and its members are pairs of option name and value. See Options below for more details. If position is given, it must be an integer starting from 0. The new download will be inserted at position in the waiting queue. 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. This method returns the GID of the newly registered download.
JSON-RPC Example
The following example adds http://example.org/file
:
>>> import urllib2, json >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.addUri', ... 'params':[['http://example.org/file']]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> c.read() '{"id":"qwer","jsonrpc":"2.0","result":"2089b05ecca3d829"}'
XML-RPC Example
The following example adds http://example.org/file
:
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.addUri(['http://example.org/file']) '2089b05ecca3d829'
The following example adds a new download with two sources and some options:
>>> s.aria2.addUri(['http://example.org/file', 'http://mirror/file'], dict(dir="/tmp")) 'd2703803b52216d1'
The following example adds a download and inserts it to the front of the queue:
>>> s.aria2.addUri(['http://example.org/file'], {}, 0) 'ca3d829cee549a4d'
[, uris[, options[, position]]])
This method adds a BitTorrent download by uploading a ".torrent" file.
If you want to add a BitTorrent Magnet URI, use the aria2.addUri()
method instead. torrent must be a base64-encoded string containing the
contents of the ".torrent" file.
uris is an array of URIs (string). uris is used for
Web-seeding. 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. 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.
See Options below for more details.
If position is given, it must be an integer starting from 0. The new
download will be inserted at position in the waiting queue. 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.
This method returns the GID of the newly registered download.
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. E.g. a
file name might be
0a3893293e27ac0490424c06de4d09242215f0a6.torrent
. If a file with the
same name already exists, it is overwritten! 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
.
The following examples add local file file.torrent
.
JSON-RPC Example
>>> import urllib2, json, base64 >>> torrent = base64.b64encode(open('file.torrent').read()) >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'asdf', ... 'method':'aria2.addTorrent', 'params':[torrent]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> c.read() '{"id":"asdf","jsonrpc":"2.0","result":"2089b05ecca3d829"}'
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.addTorrent(xmlrpclib.Binary(open('file.torrent', mode='rb').read())) '2089b05ecca3d829'
[, options[, position]])
This method adds a Metalink download by uploading a ".metalink" file.
metalink is a base64-encoded string which contains the contents of the
".metalink" file.
options is a struct and its members are pairs of option name and value.
See Options below for more details.
If position is given, it must be an integer starting from 0. The new
download will be inserted at position in the waiting queue. 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.
This method returns an array of GIDs of newly registered downloads.
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. E.g. a file name might be
0a3893293e27ac0490424c06de4d09242215f0a6.metalink
. If a file with the
same name already exists, it is overwritten! 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
.
The following examples add local file file.meta4.
JSON-RPC Example
>>> import urllib2, json, base64 >>> metalink = base64.b64encode(open('file.meta4').read()) >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.addMetalink', ... 'params':[metalink]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> c.read() '{"id":"qwer","jsonrpc":"2.0","result":["2089b05ecca3d829"]}'
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.addMetalink(xmlrpclib.Binary(open('file.meta4', mode='rb').read())) ['2089b05ecca3d829']
aria2.
remove
([secret, ]gid)This method removes the download denoted by gid (string). If the specified
download is in progress, it is first stopped. The status of the removed
download becomes removed
.
This method returns GID of removed download.
The following examples remove a download with GID#2089b05ecca3d829.
JSON-RPC Example
>>> import urllib2, json >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.remove', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> c.read() '{"id":"qwer","jsonrpc":"2.0","result":"2089b05ecca3d829"}'
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.remove('2089b05ecca3d829') '2089b05ecca3d829'
)
This method removes the download denoted by gid. 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.
aria2.
pause
([secret, ]gid)This method pauses the download denoted by gid (string). The status of
paused download becomes paused
. If the download was active, the download
is placed in the front of waiting queue. While the status is paused
,
the download is not started. To change status to waiting
, use the
aria2.unpause()
method.
This method returns GID of paused download.
aria2.
pauseAll
([secret])This method is equal to calling aria2.pause()
for every
active/waiting
download. This methods returns OK
.
)
This method pauses the download denoted by gid. 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.
aria2.
forcePauseAll
([secret])This method is equal to calling aria2.forcePause()
for
every
active/waiting download. This methods returns OK
.
)
This method changes the status of the download denoted by gid (string) from
paused
to waiting
, making the download eligible to be restarted.
This method returns the GID of the unpaused download.
aria2.
unpauseAll
([secret])This method is equal to calling aria2.unpause()
for every
paused
download. This methods returns OK
.
[, keys])
This method returns the progress of the download denoted by gid (string).
keys is an array of strings. If specified, the response contains only keys
in the keys array. If keys is empty or omitted, the response contains all
keys. This is useful when you just want specific keys and avoid unnecessary
transfers.
For example, aria2.tellStatus("2089b05ecca3d829", ["gid", "status"])
returns the gid and status keys only. The response is a struct and
contains following keys. Values are strings.
gid
status
active
for currently downloading/seeding downloads.
waiting
for downloads in the queue; download is not started.
paused
for paused downloads.
error
for downloads that were stopped because of error.
complete
for stopped and completed downloads.
removed
for the downloads removed by user.totalLength
completedLength
uploadLength
bitfield
downloadSpeed
uploadSpeed
infoHash
numSeeders
seeder
true
if the local endpoint is a seeder. Otherwise false
.
BitTorrent only.pieceLength
numPieces
connections
errorCode
errorMessage
errorCode
.followedBy
--follow-metalink
option). This value is useful to track
auto-generated downloads. If there are no such downloads, this key will not
be included in the response.following
followedBy
. A download included in
followedBy
has this object's GID in its following
value.belongsTo
dir
files
aria2.getFiles()
method.bittorrent
Struct which contains information retrieved from the .torrent (file). BitTorrent only. It contains following keys.
announceList
announce
and no announce-list
, announce
is converted to the
announce-list
format.comment
comment.utf-8
is used if available.creationDate
mode
single
or multi
.info
Struct which contains data from Info dictionary. It contains following keys.
name
name.utf-8
is used if available.verifiedLength
verifyIntegrityPending
true
if this download is waiting for the hash check in a
queue. This key exists only when this download is in the queue.JSON-RPC Example
The following example gets information about a download with GID#2089b05ecca3d829:
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.tellStatus', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': {u'bitfield': u'0000000000', u'completedLength': u'901120', u'connections': u'1', u'dir': u'/downloads', u'downloadSpeed': u'15158', u'files': [{u'index': u'1', u'length': u'34896138', u'completedLength': u'34896138', u'path': u'/downloads/file', u'selected': u'true', u'uris': [{u'status': u'used', u'uri': u'http://example.org/file'}]}], u'gid': u'2089b05ecca3d829', u'numPieces': u'34', u'pieceLength': u'1048576', u'status': u'active', u'totalLength': u'34896138', u'uploadLength': u'0', u'uploadSpeed': u'0'}}
The following example gets only specific keys:
>>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.tellStatus', ... 'params':['2089b05ecca3d829', ... ['gid', ... 'totalLength', ... 'completedLength']]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': {u'completedLength': u'5701632', u'gid': u'2089b05ecca3d829', u'totalLength': u'34896138'}}
XML-RPC Example
The following example gets information about a download with GID#2089b05ecca3d829:
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.tellStatus('2089b05ecca3d829') >>> pprint(r) {'bitfield': 'ffff80', 'completedLength': '34896138', 'connections': '0', 'dir': '/downloads', 'downloadSpeed': '0', 'errorCode': '0', 'files': [{'index': '1', 'length': '34896138', 'completedLength': '34896138', 'path': '/downloads/file', 'selected': 'true', 'uris': [{'status': 'used', 'uri': 'http://example.org/file'}]}], 'gid': '2089b05ecca3d829', 'numPieces': '17', 'pieceLength': '2097152', 'status': 'complete', 'totalLength': '34896138', 'uploadLength': '0', 'uploadSpeed': '0'}
The following example gets only specific keys:
>>> r = s.aria2.tellStatus('2089b05ecca3d829', ['gid', 'totalLength', 'completedLength']) >>> pprint(r) {'completedLength': '34896138', 'gid': '2089b05ecca3d829', 'totalLength': '34896138'}
)
This method returns the URIs used in the download denoted by gid (string). The response is an array of structs and it contains following keys. Values are string.
uri
status
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getUris', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [{u'status': u'used', u'uri': u'http://example.org/file'}]}
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getUris('2089b05ecca3d829') >>> pprint(r) [{'status': 'used', 'uri': 'http://example.org/file'}]
)
This method returns the file list of the download denoted by gid (string). The response is an array of structs which contain following keys. Values are strings.
index
path
length
completedLength
completedLength
is less than the
completedLength
returned by the aria2.tellStatus()
method.
This is because completedLength
in
aria2.getFiles()
only includes completed pieces. On the other hand, completedLength
in aria2.tellStatus()
also includes partially completed
pieces.selected
true
if this file is selected by --select-file
option. If
--select-file
is not specified or this is single-file torrent or
not a torrent download at all, this value is always true
. Otherwise
false
.uris
aria2.getUris()
method.JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getFiles', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [{u'index': u'1', u'length': u'34896138', u'completedLength': u'34896138', u'path': u'/downloads/file', u'selected': u'true', u'uris': [{u'status': u'used', u'uri': u'http://example.org/file'}]}]}
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getFiles('2089b05ecca3d829') >>> pprint(r) [{'index': '1', 'length': '34896138', 'completedLength': '34896138', 'path': '/downloads/file', 'selected': 'true', 'uris': [{'status': 'used', 'uri': 'http://example.org/file'}]}]
)
This method returns a list peers of the download denoted by gid (string). This method is for BitTorrent only. The response is an array of structs and contains the following keys. Values are strings.
peerId
ip
port
bitfield
amChoking
true
if aria2 is choking the peer. Otherwise false
.peerChoking
true
if the peer is choking aria2. Otherwise false
.downloadSpeed
uploadSpeed
seeder
true
if this peer is a seeder. Otherwise false
.JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getPeers', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [{u'amChoking': u'true', u'bitfield': u'ffffffffffffffffffffffffffffffffffffffff', u'downloadSpeed': u'10602', u'ip': u'10.0.0.9', u'peerChoking': u'false', u'peerId': u'aria2%2F1%2E10%2E5%2D%87%2A%EDz%2F%F7%E6', u'port': u'6881', u'seeder': u'true', u'uploadSpeed': u'0'}, {u'amChoking': u'false', u'bitfield': u'ffffeff0fffffffbfffffff9fffffcfff7f4ffff', u'downloadSpeed': u'8654', u'ip': u'10.0.0.30', u'peerChoking': u'false', u'peerId': u'bittorrent client758', u'port': u'37842', u'seeder': u'false', u'uploadSpeed': u'6890'}]}
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getPeers('2089b05ecca3d829') >>> pprint(r) [{'amChoking': 'true', 'bitfield': 'ffffffffffffffffffffffffffffffffffffffff', 'downloadSpeed': '10602', 'ip': '10.0.0.9', 'peerChoking': 'false', 'peerId': 'aria2%2F1%2E10%2E5%2D%87%2A%EDz%2F%F7%E6', 'port': '6881', 'seeder': 'true', 'uploadSpeed': '0'}, {'amChoking': 'false', 'bitfield': 'ffffeff0fffffffbfffffff9fffffcfff7f4ffff', 'downloadSpeed': '8654', 'ip': '10.0.0.30', 'peerChoking': 'false', 'peerId': 'bittorrent client758', 'port': '37842', 'seeder': 'false, 'uploadSpeed': '6890'}]
)
This method returns currently connected HTTP(S)/FTP/SFTP servers of the download denoted by gid (string). The response is an array of structs and contains the following keys. Values are strings.
index
servers
A list of structs which contain the following keys.
uri
currentUri
downloadSpeed
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getServers', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [{u'index': u'1', u'servers': [{u'currentUri': u'http://example.org/file', u'downloadSpeed': u'10467', u'uri': u'http://example.org/file'}]}]}
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getServers('2089b05ecca3d829') >>> pprint(r) [{'index': '1', 'servers': [{'currentUri': 'http://example.org/dl/file', 'downloadSpeed': '20285', 'uri': 'http://example.org/file'}]}]
aria2.
tellActive
([secret][,
keys])This method returns a list of active downloads. The response is an array of
the same structs as returned by the aria2.tellStatus()
method.
For the keys parameter, please refer to the aria2.tellStatus()
method.
[, keys])
This method returns a list of waiting downloads, including paused
ones.
offset is an integer and specifies the offset from
the download waiting at the front.
num is an integer and specifies the max. number of downloads to be returned.
For the keys parameter, please refer to the aria2.tellStatus()
method.
If offset is a positive integer, this method returns downloads in the range of [offset, offset + num).
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. Downloads in the response are in reversed order then.
For example, imagine three downloads "A","B" and "C" are waiting
in this order. aria2.tellWaiting(0, 1)
returns
["A"]
. aria2.tellWaiting(1, 2)
returns ["B", "C"]
.
aria2.tellWaiting(-1, 2)
returns ["C", "B"]
.
The response is an array of the same structs as returned by
aria2.tellStatus()
method.
[, keys])
This method returns a list of stopped downloads.
offset is an integer and specifies the offset from the least recently
stopped download.
num is an integer and specifies the max. number of downloads to be returned.
For the keys parameter, please refer to the aria2.tellStatus()
method.
offset and num have the same semantics as described in the
aria2.tellWaiting()
method.
The response is an array of the same structs as returned by the
aria2.tellStatus()
method.
aria2.
changePosition
([secret, ]gid, pos,
how)This method changes the position of the download denoted by
gid in the queue.
pos is an integer.
how is a string. If how is POS_SET
, it moves the download to a
position relative to the beginning of the queue. If how is POS_CUR
, it
moves the download to a position relative to the current position. If how is
POS_END
, 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.
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).
The following examples move the download GID#2089b05ecca3d829 to the front of the queue.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.changePosition', ... 'params':['2089b05ecca3d829', 0, 'POS_SET']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': 0}
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.changePosition('2089b05ecca3d829', 0, 'POS_SET') 0
aria2.
changeUri
([secret, ]gid, fileIndex,
delUris, addUris[, position])This method removes the URIs in delUris from and appends the URIs in
addUris to download denoted by gid. delUris and addUris are
lists of strings. 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 omitted, 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. 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. This
method returns a list which contains two integers. The first integer is
the number of URIs deleted. The second integer is the number of URIs
added.
The following examples add the URI http://example.org/file
to the
file whose index is 1
and belongs to the download
GID#2089b05ecca3d829.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.changeUri', ... 'params':['2089b05ecca3d829', 1, [], ['http://example.org/file']]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [0, 1]}
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.changeUri('2089b05ecca3d829', 1, [], ['http://example.org/file']) [0, 1]
)
This method returns options of the download denoted by gid. The response is a struct where keys are the names of options. The values are strings. 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.
The following examples get options of the download GID#2089b05ecca3d829.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getOption', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': {u'allow-overwrite': u'false', u'allow-piece-length-change': u'false', u'always-resume': u'true', u'async-dns': u'true', ...
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getOption('2089b05ecca3d829') >>> pprint(r) {'allow-overwrite': 'false', 'allow-piece-length-change': 'false', 'always-resume': 'true', 'async-dns': 'true', ....
)
This method changes options of the download denoted by gid (string) dynamically. options is a struct. The options listed in Input File subsection are available, except for following options:
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):
bt-max-peers
bt-request-peer-speed-limit
bt-remove-unselected-file
force-save
max-download-limit
max-upload-limit
This method returns OK
for success.
The following examples set the max-download-limit
option to 20K
for the download
GID#2089b05ecca3d829.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.changeOption', ... 'params':['2089b05ecca3d829', ... {'max-download-limit':'10K'}]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': u'OK'}
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.changeOption('2089b05ecca3d829', {'max-download-limit':'20K'}) 'OK'
aria2.
getGlobalOption
([secret])This method returns the global options. The response is a struct. Its keys
are the names of options. Values are strings.
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.
)
This method changes global options dynamically. options is a struct. The following options are available:
bt-max-open-files
download-result
keep-unfinished-download-result
log
log-level
max-concurrent-downloads
max-download-result
max-overall-download-limit
max-overall-upload-limit
optimize-concurrent-downloads
save-cookies
save-session
server-stat-of
In addition, options listed in the Input File subsection
are available, except for following options:
checksum
,
index-out
,
out
,
pause
and
select-file
.
With the log
option, you can dynamically start logging or
change log file. To stop logging, specify an empty string("") as the parameter
value. Note that log file is always opened in append mode. This method
returns OK
for success.
aria2.
getGlobalStat
([secret])This method returns global statistics such as the overall download and upload speeds. The response is a struct and contains the following keys. Values are strings.
downloadSpeed
uploadSpeed
numActive
numWaiting
numStopped
--max-download-result
option.numStoppedTotal
--max-download-result
option.JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getGlobalStat'}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': {u'downloadSpeed': u'21846', u'numActive': u'2', u'numStopped': u'0', u'numWaiting': u'0', u'uploadSpeed': u'0'}}
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getGlobalStat() >>> pprint(r) {'downloadSpeed': '23136', 'numActive': '2', 'numStopped': '0', 'numWaiting': '0', 'uploadSpeed': '0'}
aria2.
purgeDownloadResult
([secret])This method purges completed/error/removed downloads to free memory.
This method returns OK
.
)
This method removes a completed/error/removed download denoted by gid
from memory. This method returns OK
for success.
The following examples remove the download result of the download GID#2089b05ecca3d829.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.removeDownloadResult', ... 'params':['2089b05ecca3d829']}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': u'OK'}
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.removeDownloadResult('2089b05ecca3d829') 'OK'
aria2.
getVersion
([secret])This method returns the version of aria2 and the list of enabled features. The response is a struct and contains following keys.
version
enabledFeatures
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getVersion'}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': {u'enabledFeatures': [u'Async DNS', u'BitTorrent', u'Firefox3 Cookie', u'GZip', u'HTTPS', u'Message Digest', u'Metalink', u'XML-RPC'], u'version': u'1.11.0'}}
XML-RPC Example
>>> import xmlrpclib >>> from pprint import pprint >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> r = s.aria2.getVersion() >>> pprint(r) {'enabledFeatures': ['Async DNS', 'BitTorrent', 'Firefox3 Cookie', 'GZip', 'HTTPS', 'Message Digest', 'Metalink', 'XML-RPC'], 'version': '1.11.0'}
aria2.
getSessionInfo
([secret])This method returns session information. The response is a struct and contains following key.
sessionId
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.getSessionInfo'}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': {u'sessionId': u'cd6a3bc6a1de28eb5bfa181e5f6b916d44af31a9'}}
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.aria2.getSessionInfo() {'sessionId': 'cd6a3bc6a1de28eb5bfa181e5f6b916d44af31a9'}
aria2.
forceShutdown
([secret])This method shuts down aria2()
. This method behaves like
:func:'aria2.shutdown` without performing any actions which take time,
such as contacting BitTorrent trackers to unregister downloads first.
This method returns OK
.
aria2.
saveSession
([secret])This method saves the current session to a file specified by the
--save-session
option. This method returns OK
if it
succeeds.
system.
multicall
(methods)This methods encapsulates multiple method calls in a single request.
methods is an array of structs. The structs contain two keys:
methodName
and params
. methodName
is the
method name to call and params
is array containing parameters to the
method call. This method returns an array of responses. 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.
In the following examples, we add 2 downloads. The first one is
http://example.org/file
and the second one is file.torrent
.
JSON-RPC Example
>>> import urllib2, json, base64 >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'system.multicall', ... 'params':[[{'methodName':'aria2.addUri', ... 'params':[['http://example.org']]}, ... {'methodName':'aria2.addTorrent', ... 'params':[base64.b64encode(open('file.torrent').read())]}]]}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [[u'2089b05ecca3d829'], [u'd2703803b52216d1']]}
JSON-RPC additionally supports Batch requests as described in the JSON-RPC 2.0 Specification:
>>> jsonreq = json.dumps([{'jsonrpc':'2.0', 'id':'qwer', ... 'method':'aria2.addUri', ... 'params':[['http://example.org']]}, ... {'jsonrpc':'2.0', 'id':'asdf', ... 'method':'aria2.addTorrent', ... 'params':[base64.b64encode(open('file.torrent').read())]}]) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) [{u'id': u'qwer', u'jsonrpc': u'2.0', u'result': u'2089b05ecca3d829'}, {u'id': u'asdf', u'jsonrpc': u'2.0', u'result': u'd2703803b52216d1'}]
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> mc = xmlrpclib.MultiCall(s) >>> mc.aria2.addUri(['http://example.org/file']) >>> mc.aria2.addTorrent(xmlrpclib.Binary(open('file.torrent', mode='rb').read())) >>> r = mc() >>> tuple(r) ('2089b05ecca3d829', 'd2703803b52216d1')
system.
listMethods
()This method returns all the available RPC methods in an array of string. Unlike other methods, this method does not require secret token. This is safe because this method just returns the available method names.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'system.listMethods'}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [u'aria2.addUri', u'aria2.addTorrent', ...
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.system.listMethods() ['aria2.addUri', 'aria2.addTorrent', ...
system.
listNotifications
()This method returns all the available RPC notifications in an array of string. Unlike other methods, this method does not require secret token. This is safe because this method just returns the available notifications names.
JSON-RPC Example
>>> import urllib2, json >>> from pprint import pprint >>> jsonreq = json.dumps({'jsonrpc':'2.0', 'id':'qwer', ... 'method':'system.listNotifications'}) >>> c = urllib2.urlopen('http://localhost:6800/jsonrpc', jsonreq) >>> pprint(json.loads(c.read())) {u'id': u'qwer', u'jsonrpc': u'2.0', u'result': [u'aria2.onDownloadStart', u'aria2.onDownloadPause', ...
XML-RPC Example
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> s.system.listNotifications() ['aria2.onDownloadStart', 'aria2.onDownloadPause', ...
Over JSON-RPC, aria2 returns a JSON object which contains an error code in
code
and the error message in message
.
Over XML-RPC, aria2 returns faultCode=1
and the error message in
faultString
.
The same options as for --input-file
are available. See the
Input File subsection for a complete list of options.
In the option struct, the name element is the option name (without the preceding
--
) and the value element is the argument as a string.
{'split':'1', 'http-proxy':'http://proxy/'}
<struct> <member> <name>split</name> <value><string>1</string></value> </member> <member> <name>http-proxy</name> <value><string>http://proxy/</string></value> </member> </struct>
The header
and index-out
options are allowed multiple times on the command-line. Since the name should be
unique in a struct (many XML-RPC library implementations use a hash or dict for
struct), a single string is not enough. To overcome this limitation, you may use
an array as the value as well as a string.
{'header':['Accept-Language: ja', 'Accept-Charset: utf-8']}
<struct> <member> <name>header</name> <value> <array> <data> <value><string>Accept-Language: ja</string></value> <value><string>Accept-Charset: utf-8</string></value> </data> </array> </value> </member> </struct>
The following example adds a download with two options: dir
and header
.
The header
option requires two values, so it uses a list:
>>> import xmlrpclib >>> s = xmlrpclib.ServerProxy('http://localhost:6800/rpc') >>> opts = dict(dir='/tmp', ... header=['Accept-Language: ja', ... 'Accept-Charset: utf-8']) >>> s.aria2.addUri(['http://example.org/file'], opts) '1'
The JSON-RPC interface also supports requests via HTTP GET. The encoding scheme in GET parameters is based on JSON-RPC over HTTP Specification [2008-1-15(RC1)]. The encoding of GET parameters are follows:
/jsonrpc?method=METHOD_NAME&id=ID¶ms=BASE64_ENCODED_PARAMS
The method
and id
are always treated as JSON string and their
encoding must be UTF-8.
For example, The encoded string of
aria2.tellStatus('2089b05ecca3d829')
with id='foo'
looks like
this:
/jsonrpc?method=aria2.tellStatus&id=foo¶ms=WyIyMDg5YjA1ZWNjYTNkODI5Il0%3D
The params
parameter is Base64-encoded JSON array which usually
appears in params
attribute in JSON-RPC request object. In the
above example, the params is ["2089b05ecca3d829"]
, therefore:
["2089b05ecca3d829"] --(Base64)--> WyIyMDg5YjA1ZWNjYTNkODI5Il0= --(Percent Encode)--> WyIyMDg5YjA1ZWNjYTNkODI5Il0%3D
The JSON-RPC interface also supports JSONP. You can specify the callback
function in the jsoncallback
parameter:
/jsonrpc?method=aria2.tellStatus&id=foo¶ms=WyIyMDg5YjA1ZWNjYTNkODI5Il0%3D&jsoncallback=cb
For Batch requests, the method
and id
parameters must not be specified.
The whole request must be specified in the params
parameter. For example,
a Batch request:
[{'jsonrpc':'2.0', 'id':'qwer', 'method':'aria2.getVersion'}, {'jsonrpc':'2.0', 'id':'asdf', 'method':'aria2.tellActive'}]
must be encoded like this:
/jsonrpc?params=W3sianNvbnJwYyI6ICIyLjAiLCAiaWQiOiAicXdlciIsICJtZXRob2QiOiAiYXJpYTIuZ2V0VmVyc2lvbiJ9LCB7Impzb25ycGMiOiAiMi4wIiwgImlkIjogImFzZGYiLCAibWV0aG9kIjogImFyaWEyLnRlbGxBY3RpdmUifV0%3D
JSON-RPC over WebSocket uses same method signatures and response format as JSON-RPC over HTTP. The supported WebSocket version is 13 which is detailed in RFC 6455.
To send a RPC request to the RPC server, send a serialized JSON string in a Text frame. The response from the RPC server is delivered also in a Text frame.
The RPC server might send notifications to the client. Notifications is unidirectional, therefore the client which receives the notification must not respond to it. The method signature of a notification is much like a normal method request but lacks the id key. The value of the params key is the data which this notification carries. The format of the value varies depending on the notification method. Following notification methods are defined.
aria2.
onDownloadStart
(event)This notification will be sent when a download is started. The event is of type struct and it contains following keys. The value type is string.
gid
aria2.
onDownloadPause
(event)This notification will be sent when a download is paused. The event
is the same struct as the event argument of
aria2.onDownloadStart()
method.
aria2.
onDownloadStop
(event)This notification will be sent when a download is stopped by the user.
The event is the same struct as the event argument of
aria2.onDownloadStart()
method.
aria2.
onDownloadComplete
(event)This notification will be sent when a download is complete. For
BitTorrent downloads, this notification is sent when the download is
complete and seeding is over. The event is the same struct of the
event argument of
aria2.onDownloadStart()
method.
aria2.
onDownloadError
(event)This notification will be sent when a download is stopped due to an error.
The event is the same struct as the event argument of
aria2.onDownloadStart()
method.
aria2.
onBtDownloadComplete
(event)This notification will be sent when a torrent download is complete but seeding
is still going on. The event is the same struct as the event argument of
aria2.onDownloadStart()
method.
The following Ruby script adds http://localhost/aria2.tar.bz2
to
aria2c (running on localhost) with option --dir=/downloads
and
prints the RPC response:
#!/usr/bin/env ruby require 'xmlrpc/client' require 'pp' client=XMLRPC::Client.new2("http://localhost:6800/rpc") options={ "dir" => "/downloads" } result=client.call("aria2.addUri", [ "http://localhost/aria2.tar.bz2" ], options) pp result
If you are a Python lover, you can use xmlrpclib (Python3 uses xmlrpc.client instead) to interact with aria2:
import xmlrpclib from pprint import pprint s = xmlrpclib.ServerProxy("http://localhost:6800/rpc") r = s.aria2.addUri(["http://localhost/aria2.tar.bz2"], {"dir":"/downloads"}) pprint(r)