Aria2JsonRpc
NAME
Aria2JsonRpc - Python wrapper for the Aria2 RPC server.
CLASSES
builtins.Exception(builtins.BaseException)
Aria2JsonRpcError
builtins.object
Aria2JsonRpc
Aria2RpcServer
FakeLock
class Aria2JsonRpc(builtins.object)
| Aria2JsonRpc(identity, uri, mode='normal', token=None, http_user=None, http_passwd=None, server_cert=None, client_cert=None, client_cert_password=None, ssl_protocol=None, setup_function=None)
|
| Interface class for interacting with an Aria2 RPC server.
|
| Methods defined here:
|
| __init__(self, identity, uri, mode='normal', token=None, http_user=None, http_passwd=None, server_cert=None, client_cert=None, client_cert_password=None, ssl_protocol=None, setup_function=None)
| identity: the identity to send to the RPC interface
|
| uri: the URI of the RPC interface
|
| mode:
| normal - process requests immediately
| batch - queue requests (run with "process_queue")
| format - return RPC request objects
|
| token:
| RPC method-level authorization token (set using `--rpc-secret`)
|
| http_user, http_password:
| HTTP Basic authentication credentials (deprecated)
|
| server_cert:
| server certificate for HTTPS connections
|
| client_cert:
| client certificate for HTTPS connections
|
| client_cert_password:
| prompt for client certificate password
|
| ssl_protocol:
| SSL protocol from the ssl module
|
| setup_function:
| A function to invoke prior to the first server call. This could be the
| launch() method of an Aria2RpcServer instance, for example. This attribute
| is set automatically in instances returned from Aria2RpcServer.get_a2jr()
|
| addMetalink(self, metalink, options=None, position=None)
| aria2.addMetalink method
|
| metalink: base64-encoded metalink file
|
| options: dictionary of additional options
|
| position: position in queue
|
| Returns an array of GIDs.
|
| addTorrent(self, torrent, uris=None, options=None, position=None)
| aria2.addTorrent method
|
| torrent: base64-encoded torrent file
|
| uris: list of webseed URIs
|
| options: dictionary of additional options
|
| position: position in queue
|
| Returns a GID.
|
| addUri(self, uris, options=None, position=None)
| aria2.addUri method
|
| uris: list of URIs
|
| options: dictionary of additional options
|
| position: position in queue
|
| Returns a GID
|
| add_HTTPBasicAuthHandler(self, user, passwd)
| Add a handler for HTTP Basic authentication.
|
| If either user or passwd are None, the handler is removed.
|
| add_HTTPSHandler(self, server_cert=None, client_cert=None, client_cert_password=None, protocol=None)
| Add a handler for HTTPS connections with optional server and client
| certificates.
|
| add_metalink(self, path, options=None, position=None)
| A wrapper around addMetalink for loading files.
|
| add_torrent(self, path, uris=None, options=None, position=None)
| A wrapper around addTorrent for loading files.
|
| changeGlobalOption(self, options)
| aria2.changeGlobalOption method
|
| options: dictionary of new options
|
| changeOption(self, gid, options)
| aria2.changeOption method
|
| gid: GID to change
|
| options: dictionary of new options
| (not all options can be changed for active downloads)
|
| changePosition(self, gid, pos, how)
| aria2.changePosition method
|
| gid: GID to change
|
| pos: the position
|
| how: "POS_SET", "POS_CUR" or "POS_END"
|
| changeUri(self, gid, fileIndex, delUris, addUris, position=None)
| aria2.changePosition method
|
| gid: GID to change
|
| fileIndex: file to affect (1-based)
|
| delUris: URIs to remove
|
| addUris: URIs to add
|
| position: where URIs are inserted, after URIs have been removed
|
| forcePause(self, gid)
| aria2.forcePause method
|
| gid: GID to pause
|
| forcePauseAll(self)
| aria2.forcePauseAll method
|
| forceRemove(self, gid)
| aria2.forceRemove method
|
| gid: GID to remove
|
| forceShutdown(self)
| aria2.forceShutdown method
|
| getFiles(self, gid)
| aria2.getFiles method
|
| gid: GID to query
|
| Returns a list of dictionaries.
|
| getGlobalOption(self)
| aria2.getGlobalOption method
|
| Returns a dictionary.
|
| getGlobalStat(self)
| aria2.getGlobalStat method
|
| Returns a dictionary.
|
| getOption(self, gid)
| aria2.getOption method
|
| gid: GID to query
|
| Returns a dictionary of options.
|
| getPeers(self, gid)
| aria2.getPeers method
|
| gid: GID to query
|
| Returns a list of dictionaries.
|
| getServers(self, gid)
| aria2.getServers method
|
| gid: GID to query
|
| Returns a list of dictionaries.
|
| getSessionInfo(self)
| aria2.getSessionInfo method
|
| Returns a dictionary.
|
| getUris(self, gid)
| aria2.getUris method
|
| gid: GID to query
|
| Returns a list of dictionaries.
|
| getVersion(self)
| aria2.getVersion method
|
| Returns a dictionary.
|
| get_status(self, gid)
| Get the status of a single GID.
|
| get_statuses(self, gids)
| Get the status of multiple GIDs. The status of each is yielded in order.
|
| iter_handlers(self)
| Iterate over handlers.
|
| jsonrpc(self, method, params=None, prefix='aria2.')
| POST a request to the RPC interface.
|
| multicall(self, methods)
| aria2.multicall method
|
| methods: list of dictionaries (keys: methodName, params)
|
| The method names must be those used by Aria2c, e.g. "aria2.tellStatus".
|
| pause(self, gid)
| aria2.pause method
|
| gid: GID to pause
|
| pauseAll(self)
| aria2.pauseAll method
|
| polymethod_download(self, downloads, interval=1)
| Enqueue a series of downloads and wait for them to finish. Iterate over the
| status of each, in order.
|
| downloads:
| An iterable over (<type>, <args>, ...) where <type> indicates the "add"
| method to use ('addUri', 'addTorrent', 'addMetalink') and everything that
| follows are arguments to pass to that method.
|
| interval:
| The status check interval while waiting.
|
| Iterates over the download status of finished downloads. "complete"
| indicates success. Lists of statuses will be returned for downloads that
| create multiple GIDs (e.g. metalinks).
|
| polymethod_download_bool(self, *args, **kwargs)
| A wrapper around polymethod_download() which returns a boolean for each
| download to indicate success (True) or failure (False).
|
| polymethod_enqueue_many(self, downloads)
| Enqueue downloads.
|
| downloads: Same as polymethod_download().
|
| polymethod_enqueue_one(self, download)
| Same as polymethod_enqueue_many but for one element.
|
| polymethod_wait_many(self, gid_lists, interval=1)
| Wait for the GIDs to complete or fail and return their statuses.
|
| gids:
| A list of lists of GIDs.
|
| print_global_status(self)
| Print global status of the RPC server.
|
| process_queue(self)
| Processed queued requests.
|
| purgeDownloadResult(self)
| aria2.purgeDownloadResult method
|
| queue_uris(self, uris, options, interval=None)
| Enqueue URIs and wait for download to finish while printing status at
| regular intervals.
|
| remove(self, gid)
| aria2.remove method
|
| gid: GID to remove
|
| removeDownloadResult(self, gid)
| aria2.removeDownloadResult method
|
| gid: GID to remove
|
| remove_HTTPBasicAuthHandler(self)
| Remove the HTTP Basic authentication handler.
|
| remove_HTTPSHandler(self)
| Remove the HTTPS handler.
|
| remove_handler(self, name)
| Remove a handler.
|
| send_request(self, req_obj)
| Send the request and return the response.
|
| shutdown(self)
| aria2.shutdown method
|
| tellActive(self, keys=None)
| aria2.tellActive method
|
| keys: same as tellStatus
|
| Returns a list of dictionaries. The dictionaries are the same as those
| returned by tellStatus.
|
| tellStatus(self, gid, keys=None)
| aria2.tellStatus method
|
| gid: GID to query
|
| keys: subset of status keys to return (all keys are returned otherwise)
|
| Returns a dictionary.
|
| tellStopped(self, offset, num, keys=None)
| aria2.tellStopped method
|
| offset: offset from oldest download (same semantics as tellWaiting)
|
| num: same as tellWaiting
|
| keys: same as tellStatus
|
| Returns a list of dictionaries. The dictionaries are the same as those
| returned by tellStatus.
|
| tellWaiting(self, offset, num, keys=None)
| aria2.tellWaiting method
|
| offset: offset from start of waiting download queue
| (negative values are counted from the end of the queue)
|
| num: number of downloads to return
|
| keys: same as tellStatus
|
| Returns a list of dictionaries. The dictionaries are the same as those
| returned by tellStatus.
|
| unpause(self, gid)
| aria2.unpause method
|
| gid: GID to unpause
|
| unpauseAll(self)
| aria2.unpauseAll method
|
| update_opener(self)
| Build an opener from the current handlers.
|
| wait_for_final_status(self, gid, interval=1)
| Wait for a GID to complete or fail and return its status.
|
| wait_for_final_statuses(self, gids, interval=1)
| Wait for multiple GIDs to complete or fail and return their statuses in
| order.
|
| gids:
| A flat list of GIDs.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| b64encode_file(path)
| Read a file into a base64-encoded string.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class Aria2JsonRpcError(builtins.Exception)
| Aria2JsonRpcError(msg, connection_error=False)
|
| Base exception raised by this module.
|
| Method resolution order:
| Aria2JsonRpcError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Methods defined here:
|
| __init__(self, msg, connection_error=False)
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class Aria2RpcServer(builtins.object)
| Aria2RpcServer(cmd, token, port, identity, a2jr_kwargs=None, timeout=10, scheme='http', host='localhost', nice=True, lock=None, quiet=True)
|
| Wrapper to manage starting and stopping an Aria2 RPC server within a context
| manager.
|
| Methods defined here:
|
| __enter__(self)
| Same as launch().
|
| __exit__(self, exc_type, exc_value, traceback)
| Invokes kill()
|
| __init__(self, cmd, token, port, identity, a2jr_kwargs=None, timeout=10, scheme='http', host='localhost', nice=True, lock=None, quiet=True)
| cmd:
| A list representing the aria2c command to be run along with additional
| arguments, eg.
|
| ['aria2c', '--rpc-listen-all=false', '--continue']
|
| or
|
| ['sudo', 'aria2c', '--rpc-listen-all=false', '--continue']
|
| This MUST NOT contain any of the following options:
|
| --enable-rpc
| --rpc-secret
| --rpc-listen-port
|
| For local use it is recommended to include "--rpc-listen-all=false".
|
| token:
| The RPC token to pass to aria2c's --rpc-secret option.
|
| port:
| The RPC listen port to pass to aria2c's --rpc-listen-port option.
|
| identity:
| The identity to use in the Aria2JsonRpc returned by __enter__.
|
| args:
| Additional arguments to aria2c. These must not include --rpc-secret or
| --rpc-listen-port.
|
| a2jr_kwargs:
| Keyword arguments to pass to Aria2JsonRpc.
|
| timeout:
| The timeout when waiting for the server to shut down.
|
| nice:
| Default value of "nice" argument to kill() method.
|
| lock:
| An optional threading/multiprocessing lock object that can be used as a
| context manager to lock the launch method when starting and stopping the
| server.
|
| quiet:
| If True, suppress output from the RPC server if one is launched.
|
| get_a2jr(self, new=False)
| Get an instance of Aria2JsonRpc to interface with the server. This instance
| will have its setup_function attribute set so that it can launch the server
| dynamically before the first request is sent.
|
| kill(self, nice=None)
| Stop the Aria2c RPC server launched by this object if there is one.
|
| nice:
| If True, use the RPC "shutdown" method before trying the "forceShutdown"
| method. This waits up to 3 seconds even if there are no current downloads.
|
| launch(self)
| Launch an instance of the server if necessary and return an Aria2JsonRpc
| object to interface with it.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class FakeLock(builtins.object)
| Dummy context manager to be used as a lock placeholder.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_value, traceback)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
FUNCTIONS
a2jr_from_args(identity, args)
Return a new Aria2JsonRpc object using the provided arguments.
See `add_server_arguments`.
add_options_and_position(params, options=None, position=None)
Convenience method for adding options and position to parameters.
add_server_arguments(parser)
Common command-line arguments for the server.
Accepts an argparse ArgumentParser or group.
format_bytes(size)
Convert bytes to a human-friendly units..
format_seconds(seconds)
Convert seconds to hours, minutes and seconds.
get_status(response)
Process a status response.
random_token(length, valid_chars=None)
Get a random secret token for the Aria2 RPC server.
length:
The length of the token
valid_chars:
A list or other ordered and indexable iterable of valid characters. If not
given of None, asciinumberic characters with some punctuation characters
will be used.
to_json_list(objs)
Wrap strings in lists. Other iterables are converted to lists directly.
DATA
ARIA2_CONTROL_FILE_EXT = '.aria2'
DEFAULT_PORT = 6800
FINAL_STATUS = ('complete', 'error')
JSON_ENCODING = 'utf-8'
LOGGER = <Logger Aria2JsonRpc (WARNING)>
SERVER_URI_FORMAT = '{}://{}:{:d}/jsonrpc'
TEMPORARY_STATUS = ('active', 'waiting', 'paused')