命令行工具和库,用于与带有json-rpc的aria2c守护进程交互。

aria2p的Python项目详细描述


aria2p

pipeline statuscoverage reportdocumentationpypi versionGitter

命令行工具和python库,通过json-rpc与^{}守护进程交互。

避免混淆:

  • aria2是一个轻量级的多协议、多源、跨平台的下载实用程序,在命令行中操作。 它支持http/https、ftp、sftp、bittorrent和metalink。
  • aria2c是由aria2提供的命令行可执行文件的名称。它可以充当守护进程。
  • aria2pp对于python)是一个可以与aria2c守护进程交互的命令行客户机。 它不是官方客户。还有其他python包允许您与aria2c守护进程交互。 这些其他的包没有提供足够的可用性(在我看来),这就是我开发aria2p的原因。

purposearia2c可以在前台、一次性下载或后台作为守护进程运行。 这就是aria2p介入的地方:当aria2c的实例在后台运行时, aria2p将能够与它通信,以便向队列中添加下载、删除、暂停或恢复下载,等等。

为了使aria2p能够与aria2c进程通信,必须启用rpc模式 使用--enable-rpc选项。rpc代表Remote Procedure Call。 尽管aria2c同时支持json-rpc和xml-rpc协议,但aria2p仅与json一起工作(而不是xml)。 有关如何配置aria2c作为启用rpc模式的守护进程运行的详细信息 可以在文档的Configuration section中找到。

要求

aria2p需要python 3.6或更高版本。

<详细信息>要安装python 3.6,我建议使用^{}
# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv

# setup pyenv (you should also put these three lines in .bashrc or similar)exportPATH="${HOME}/.pyenv/bin:${PATH}"exportPYENV_ROOT="${HOME}/.pyenv"eval"$(pyenv init -)"# install Python 3.6
pyenv install 3.6.8

# make it available globally
pyenv global system 3.6.8

您还必须安装aria2。在具有apt-get

的系统上
sudo apt-get install aria2

安装

使用pip

python3.6 -m pip install aria2p

使用^{}

python3.6 -m pip install --user pipx

pipx install --python python3.6 aria2p

使用(作为库)

此库仍在工作中。稍后将添加更多示例。 同时,您可以阅读官方文档上的Reference section

importaria2p# initialization, these are the default valuesaria2=aria2p.API(aria2p.Client(host="http://localhost",port=6800,secret=""))# list downloadsdownloads=aria2.get_downloads()fordownloadindownloads:print(download.name,download.download_speed)# add downloadsmagnet_uri="magnet:?xt=urn:..."download=aria2.add_magnet(magnet_uri)

用法(命令行)

usage: aria2p [GLOBAL_OPTS...] COMMAND [COMMAND_OPTS...]

Command-line tool and Python library to interact with an `aria2c` daemon
process through JSON-RPC.

Global options:
  -h, --help            Show this help message and exit. Commands also accept
                        the -h/--help option.
  -p PORT, --port PORT  Port to use to connect to the remote server.
  -H HOST, --host HOST  Host address for the remote server.
  -s SECRET, --secret SECRET
                        Secret token to use to connect to the remote server.
  -L {TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL}, --log-level {TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL}
                        Log level to use

Commands:
  
    add-magnet          Add a download with a Magnet URI.
    add-metalink        Add a download with a Metalink file.
    add-torrent         Add a download with a torrent file.
    autopurge (autoclear)
                        Automatically purge completed/removed/failed
                        downloads.
    call                Call a remote method through the JSON-RPC client.
    pause (stop)        Pause downloads.
    pause-all           Pause all downloads.
    purge (clear)       Purge downloads.
    remove (rm, del, delete)
                        Remove downloads.
    remove-all          Remove all downloads.
    resume (start)      Resume downloads.
    resume-all          Resume all downloads.
    show                Show the download progression.

在没有任何参数的情况下调用aria2p将默认调用show命令, 显示当前下载的列表:

GID  STATUS  PROGRESS  DOWN_SPEED  UP_SPEED  ETA  NAME

还没有交互模式, 但是可以将watchshow子命令结合使用 查看下载进度:

watch -t -n1 aria2p show

命令:

警告:不推荐使用以-all结尾的命令。请将它们与-a--all选项一起使用 (例如,使用pause -a,而不是pause-all)。这些命令将在0.5.0版中删除。


add-magnet

usage: aria2p add-magnet [-h] uri

Add a download with a Magnet URI.

positional arguments:
  uri         The magnet URI to use.

optional arguments:
  -h, --help  Show this help message and exit.


add-metalink

usage: aria2p add-metalink [-h] metalink_file

Add a download with a Metalink file.

positional arguments:
  metalink_file  The path to the metalink file.

optional arguments:
  -h, --help     Show this help message and exit.


add-torrent

usage: aria2p add-torrent [-h] torrent_file

Add a download with a torrent file.

positional arguments:
  torrent_file  The path to the torrent file.

optional arguments:
  -h, --help    Show this help message and exit.


autopurge

usage: aria2p autopurge [-h]

Automatically purge completed/removed/failed downloads.

optional arguments:
  -h, --help  Show this help message and exit.


call

usage: aria2p call [-h] [-P PARAMS [PARAMS ...] | -J PARAMS] method

Call a remote method through the JSON-RPC client.

positional arguments:
  method                The method to call (case insensitive). Dashes and
                        underscores will be removed so you can use as many as
                        you want, or none. Prefixes like 'aria2.' or 'system.'
                        are also optional.

optional arguments:
  -h, --help            Show this help message and exit.
  -P PARAMS [PARAMS ...], --params-list PARAMS [PARAMS ...]
                        Parameters as a list of strings.
  -J PARAMS, --json-params PARAMS
                        Parameters as a JSON string. You should always wrap it
                        at least once in an array '[]'.

如帮助文本中所述, method可以是确切的方法名, 或者只是没有前缀的名字。 它不区分大小写,破折号和下划线将被删除。

以下都是等效的:

  • aria2.addUri
  • aria2.adduri
  • addUri
  • ADDURI
  • aria2.ADD-URI
  • add_uri
  • A-d_D-u_R-i(是有效的)
  • A---R---I---A---2.a__d__d__u__r__i(我想你明白了)
  • 更丑陋的形式…

示例

列出所有可用的方法。 此示例使用^{}

$ aria2p call listmethods | jq
[  "aria2.addUri",  "aria2.addTorrent",  "aria2.getPeers",  "aria2.addMetalink",  "aria2.remove",  "aria2.pause",  "aria2.forcePause",  "aria2.pauseAll",  "aria2.forcePauseAll",  "aria2.unpause",  "aria2.unpauseAll",  "aria2.forceRemove",  "aria2.changePosition",  "aria2.tellStatus",  "aria2.getUris",  "aria2.getFiles",  "aria2.getServers",  "aria2.tellActive",  "aria2.tellWaiting",  "aria2.tellStopped",  "aria2.getOption",  "aria2.changeUri",  "aria2.changeOption",  "aria2.getGlobalOption",  "aria2.changeGlobalOption",  "aria2.purgeDownloadResult",  "aria2.removeDownloadResult",  "aria2.getVersion",  "aria2.getSessionInfo",  "aria2.shutdown",  "aria2.forceShutdown",  "aria2.getGlobalStat",  "aria2.saveSession",  "system.multicall",  "system.listMethods",  "system.listNotifications"]

列出所有活动下载的gid(标识符)。 请注意,我们必须将参数作为json字符串提供。

$ aria2p call tellactive -J '[["gid"]]'[{"gid": "b686cad55029d4df"}, {"gid": "4b39a1ad8fd94e26"}, {"gid": "9d331cc4b287e5df"}, {"gid": "8c9de0df753a5195"}]

使用gid暂停下载。 注意,当需要单个字符串参数时,可以将其传递给dir直接用-P

$ aria2p call pause -P b686cad55029d4df
"b686cad55029d4df"

使用magnet uri添加下载。 此示例使用jq -r删除结果周围的引号。

$ aria2p call adduri -J '[["magnet:?xt=urn:..."]]'| jq -r
4b39a1ad8fd94e26f

清除下载结果(从列表中删除已完成的下载)。

$ aria2p call purge_download_result
"OK"

pause

usage: aria2p pause [-h] [-a] [-f] [gids [gids ...]]

Pause downloads.

positional arguments:
  gids         The GIDs of the downloads to pause.

optional arguments:
  -h, --help   Show this help message and exit.
  -a, --all    Pause all the downloads.
  -f, --force  Pause without contacting servers first.


pause-all

usage: aria2p pause-all [-h] [-f]

Pause all downloads.

optional arguments:
  -h, --help   Show this help message and exit.
  -f, --force  Pause without contacting servers first.


purge

usage: aria2p purge [-h] [-a] [gids [gids ...]]

Purge downloads.

positional arguments:
  gids        The GIDs of the downloads to purge.

optional arguments:
  -h, --help  Show this help message and exit.
  -a, --all   Purge all the downloads.


remove

usage: aria2p remove [-h] [-a] [-f] [gids [gids ...]]

Remove downloads.

positional arguments:
  gids         The GIDs of the downloads to remove.

optional arguments:
  -h, --help   Show this help message and exit.
  -a, --all    Remove all the downloads.
  -f, --force  Remove without contacting servers first.


remove-all

usage: aria2p remove-all [-h] [-f]

Remove all downloads.

optional arguments:
  -h, --help   Show this help message and exit.
  -f, --force  Remove without contacting servers first.


resume

usage: aria2p resume [-h] [-a] [gids [gids ...]]

Resume downloads.

positional arguments:
  gids        The GIDs of the downloads to resume.

optional arguments:
  -h, --help  Show this help message and exit.
  -a, --all   Resume all the downloads.


resume-all

usage: aria2p resume-all [-h]

Resume all downloads.

optional arguments:
  -h, --help  Show this help message and exit.


show

usage: aria2p show [-h]

Show the download progression.

optional arguments:
  -h, --help  Show this help message and exit.

故障排除

  • 使用aria2p作为python库时出现如下错误输出:

    requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=6800): Max retries exceeded with url: /jsonrpc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1115b1908>: Failed to establish a new connection: [Errno 61] Connection refused',))
    

    解决方案:aria2c需要先启动并运行。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java调用Python函数作为TEID中的UDF   java Android。支持v4导入不工作   java如何影响具有静态属性的类   java如何在从glTexImage2D()分配后编辑纹理的像素颜色   javaspringboot+rediscache+@Cacheable适用于某些方法,而不适用于其他方法   java无法将动态Web模块方面从3.0更改为2.5   java如何在新选项卡中显示打印的文档?   java Google Cloud Endpoints API方法仅在删除用户参数时成功调用   java为什么我可以使用Stack<Double>但不能使用Stack<Double>?   java JDBC PreparedStatement似乎忽略了占位符   java如何设置JInternalFrame的标准图标化位置?   Java文件。copy()不复制文件   基于另一个类的java显示arraylist?   java Android Studio:错误:非法字符:'\u2028'   对象(Java)无法实例化类型映像?   javascript错误:飞行前响应的HTTP状态代码401无效   java确保泛型vararg参数具有相同的类型