Skip to content

Instantly share code, notes, and snippets.

@v1k45
Last active January 17, 2023 09:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v1k45/2b3516c9a54d221910b3598244b7de89 to your computer and use it in GitHub Desktop.
Save v1k45/2b3516c9a54d221910b3598244b7de89 to your computer and use it in GitHub Desktop.
Helper class to interact with Aria2 XMLRPC

Helper class for ease interaction with aria2's XMLRPC interface.

All aria2 methods require the first parameter to be the RPC Secret. This makes us pass the token for each rpc like:

from xmlrpc.client import ServerProxy

RPC_TOKEN = 'token:rpc_secret_token'

aria2 = ServerProxy(url="http://aria2-host:6800/rpc").aria2
aria2.getVersion(RPC_TOKEN)
aria2.addURI(RPC_TOKEN, ['https://piratebay.org/torrents/ubuntu.iso.torrent'])

system = ServerProxy(url="http://aria2-host:6800/rpc").system
system.listMethods()
system.listNotifications()

Is simplified into:

from .downloaders import Aria2

aria2 = Aria2().aria2
aria2.getVersion()
aria2.addURI(['https://piratebay.org/torrents/ubuntu.iso.torrent'])

system = Aria2().system
system.listMethods()
from xmlrpc.client import ServerProxy
class Aria2(ServerProxy):
def __init__(self, *args, **kwargs):
url = "http://aria2-host:6800/rpc"
super().__init__(url, *args, **kwargs)
def _ServerProxy__request(self, methodname, params):
params = ("token:rpc_secret_token", *params)
return super(Aria2, self)._ServerProxy__request(methodname, params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment