QBitTorrent 4.1+的Python包装程序(Web API v2.2+)
qbittorrent-api的Python项目详细描述
QBitTorrent v4.1+Web API客户端
QBitTorrent Web API的Python客户端实现。
支持QBitTorrent v4.1.0及更高版本。此客户端与QBitTorrent的Web API v2.2及更高版本交互。
安装
qbittorrent api可在python包索引(pypi)上找到。
https://pypi.org/project/qbittorrent-api/
您可以使用以下技术之一安装qbittorrent api:
- 使用pip:
pip安装qbittorrent api
- 从pypi下载.zip或.tar.gz文件并安装
- 从github下载源代码并安装
https://github.com/rmartin16/qbittorrent-api
请确保同时安装请求和attrdict。
确保在QBitTorrent中启用WebUI:工具->;首选项->;Web UI
开始
fromqbittorrentapiimportClientclient=Client(host='localhost:8080',username='admin',password='adminadmin')print("qBittorrent Version: %s"%client.app_version())help(Client)
配置
- 为https webui使用不受信任的证书(例如自签名的证书)
- 在实例化客户机时设置
verify庘webui庘certificate=true
或将环境变量python庘qbittorrentapi庘do庘verify庘webui庘certificate
设置为非空值。 - 否则将导致与QBitTorrent的连接失败。
- 注意,这样做实际上会关闭证书验证。因此,例如,不会检测和报告潜在的中间人攻击(因为错误被抑制)。但是,连接将保持加密。
- 在实例化客户机时设置
- 主机、用户名和密码默认值
- 在实例化客户机或调用client.auth_登录(username='…',password='…')时,可以提供这些功能。
- 或者,设置环境变量
python qbittorrentapi主机
,python qbittorrentapi用户名
和python qbittorrentapi密码
- 尚未在QBittoreRent主机中实现API终结点
- 默认情况下,如果对主机上尚不存在的终结点(如搜索终结点API v2.1.1)进行调用,则会有调试记录器输出,并且不会返回任何输出。
- 用
raise_unimplementederror_for_unimplemented_api_endpoints=true初始化客户机
- 禁用日志调试输出
- 在实例化客户端或手动禁用日志记录时,设置
disable_logging_debug_output=true
:logging.getlogger('qbittorrentapi').setlevel(logging.info)
logging.getlogger('requests').setlevel(logging.info)
logging.getlogger('urllib3').setlevel(logging.info)
- 在实例化客户端或手动禁用日志记录时,设置
直接API端点访问
到直接api端点的接口是稳定的,需要向后兼容。
api被分隔成8个api端点的命名空间:
- 身份验证(auth)
- 应用程序(app)
- 对数(对数)
- 同步(sync)
- 传输(传输)
- Torrent管理(Torrent)
- RSS(RSS)
- 搜索(搜索)
要使用此包直接访问这些端点:
response=client.<name>_<apimethod>(<arguments>)
将<;name>;
替换为上面八个命名空间之一,并将<;api method>;
替换为相关终结点。
例如:
torrent_list=client.torrents_info(status_filter='active')
api调用的响应将是字符串或端点的专用对象。一般来说,非字符串响应是扩展字典和列表。
交互层使用
该包还包含到api端点的更健壮的接口。为了八个命名空间中的每一个都有一个到相关api端点的接口。
应用程序命名空间的示例:
ver=client.app.versionapi_ver=client.app.api_web_versionprefs=client.app.preferencesis_dht_enabled=client.application.preferences.dhtclient.application.preferences=dict(dht=(notis_dht_enabled))
对于每个命名空间,没有参数或返回值的任何终结点都作为属性实现。所有其他端点都作为方法实现;其中一些方法还具有扩展的用法。
例如,日志/主终结点具有扩展的用法:
complete_log=client.log.main()normal_log=client.log.main.normal()warning_log=client.log.main.warning()critical_log=client.log.main.critical()
最扩展的命名空间是Torrents。
# Gathering torrentstorrent_list=client.torrents.info()torrent_list_active=client.torrents.info.active()torrent_list_active_partial=client.torrents.active(limit=100,offset=200)torrent_list_downloading=client.torrents.info.downloading()# Torrent loopingfortorrentintorrent_list:print(torrent.name)# Actions for multiple torrentsclient.torrents.pause(hashes=['...','...'])client.torrents.recheck(hashes=['...','...'])# or just do all torrent client.torrents.pause.all()client.torrents.recheck.all()client.torrents.resume.all()
一旦你有了一个激流,也会有一连串的互动。
hash=torrent.info.hash# as well the rest fo the properties from torrents/info endpointproperties=torrent.propertiestrackers=torrent.trackersfiles=torrent.files# Action methodstorrent.edit_tracker(original_url="...",new_url="...")torrent.remove_trackers(urls='http://127.0.0.2/')torrent.rename(new_torrent_name="...")torrent.resume()torrent.pause()torrent.recheck()torrent.torrents_top_priority()torrent.set_location(location='/home/user/torrents/')torrent.set_category(category='video')
对于命名空间可用的所有终结点,此操作都将继续。
搜索还具有扩展的用途。
search_job=client.search.start(pattern='Ubuntu',categories='all',plugins='all')whileTrue:ifsearch_job.status()[0].status=='Stopped':breakprint(search_job.results())search_job.delete()
交互层注释
- 所有终结点都可以使用,但不附加终结点的命名空间。
- 因此,
client.torrents.torrents_resume()
和client.torrents.resume()
是相同的。 - 这也扩展到以空格命名的端点。因此,
web api版本
和webapi版本
是相同的。
- 因此,
- 调用api调用时,可以使用python代码中实现的参数或api文档中指定的参数。
- 因此,
Torrents_rename(hash='…',new_torrent_name="…"
和Torrents_rename(hash='…',name="…"
是相同的。
- 因此,
交互层详细信息
- 应用程序
- 属性
- 版本
- Web API版本
- 构建信息
- 默认保存路径
- 首选项(支持分配)
- 关机
方法 - 属性
- 主
- 同行
- 主数据
- Torrent_对等
- 属性
- 信息
- 速度限制模式(支持分配)
- 下载限制(支持分配)
- 上传限制(支持分配)
- 设置下载限制
- 设置上载限制
- 切换速度限制模式
- 信息
- 继续
- 暂停
- 删除
- 重新检查
- 再名词
- 提高优先级
- 降低优先级
- 最高优先级
- 最低优先级
- 下载限制
- 设置下载限制
- 设置共享限制
- 上传限制
- 设置上载限制
- 设置位置
- 设置类别
- 设置自动管理
- 切换顺序下载
- 切换"第一件"和"最后一件"优先级
- 设置强制启动
- 设置超级播种
- 属性
- 信息
- 属性
- 跟踪器
- 网络种子
- 文件
- 工件状态
- 碎片散列
- 下载限制(支持分配)
- 上传限制(支持分配)
- 添加跟踪程序
- 编辑追踪程序
- 删除跟踪程序
- 文件优先级
- 文件优先级
- 重命名
- 设置位置
- 设置类别
- 设置自动管理
- 设置强制进给
- 设置超级播种
- 以及上面所有的Torrents方法
- 属性
- 类别
- 创建类别
- 编辑类别
- 删除类别
- 属性
- 规则
- 添加文件夹
- 添加馈送
- 删除项目
- 移动项目
- 项目
- 项目。无数据
- items.woth_数据
- 设置规则
- 重命名规则
- 删除规则
- 属性
- 插件
- 开始
- 停止
- 状态 <李>结果
- 停止
- 结果
- 状态
- 删除
例外情况
类APIError(异常): 通过< /P>
类登录失败(APIError): 通过< /P>
类apiconnectionerror(apierror): 通过< /P>
类HttpError(APIError): 通过< /P>
类http400error(httperror): 通过< /P>
类http401error(httperror): 通过< /P>
类http403error(httperror): 通过< /P>
类http404error(httperror): 通过< /P>
类http409error(httperror): 通过< /P>
类http415error(httperror): 通过< /P>
类http500error(httperror): 通过< /P>
类MissingRequiredParameters400错误(Http400错误): 通过< /P>
类InvalidRequest400error(Http400error): 通过< /P>
类未授权401错误(http401错误): 通过< /P>
类禁止403error(http403error): 通过< /P>
类NotFound404error(Http404error): 通过< /P>
类冲突409错误(http409错误): 通过< /P>
类UnsupportedMediaType415error(Http415error): 通过< /P>
类internalservererror500error(http500error): 通过< /P>