qbittorrent>3.1.x的python包装器
python-qbittorrent的Python项目详细描述
qbittorrent web api的python包装器(用于v3.1.x以上的版本)。
对于具有早期版本的qbittorrent客户端,请使用mookfist的python-qbittorrent。
此包装基于qBittorrent’s Official Web API Documentation
中描述的方法一些方法仅在qbittorent的最新版本(编写时为v3.3.1)中受支持。
最好将客户端升级到最新版本。
安装
最好的方法是从pypi安装一个稳定的版本:
$ pip install python-qbittorrent
您还可以留在包裹的边缘:
$ git clone https://github.com/v1k45/python-qBittorrent.git $ cd python-qBittorrent $ python setup.py install
快速使用指南
fromqbittorrentimportClientqb=Client('http://127.0.0.1:8080/')qb.login('admin','your-secret-password')# not required when 'Bypass from localhost' setting is active.# defaults to admin:admin.# to use defaults, just do qb.login()torrents=qb.torrents()fortorrentintorrents:printtorrent['name']
API方法
获取torrents
获取所有activetorrents:
qb.torrents()
过滤种子:
qb.torrents(filter='downloading', category='my category') # This will return all torrents which are currently # downloading and are labeled as ``my category``. qb.torrents(filter='paused', sort='ratio') # This will return all paused torrents sorted by their Leech:Seed ratio.
有关所有可能的筛选器,请参阅qbittorents web api文档。
下载Torrents
通过链接下载Torrents:
magnet_link = "magnet:?xt=urn:btih:e334ab9ddd91c10938a7....." qb.download_from_link(magnet_link) # No matter the link is correct or not, # method will always return empty JSON object.
按链接列表下载多个Torrent:
link_list = [link1, link2, link3] qb.download_from_link(link_list)
按文件下载种子:
torrent_file = open('my-torrent-file.torrent', 'rb') qb.download_from_file(torrent_file)
使用文件下载多个Torrent:
torrent_file_list = [open('1.torrent', 'rb'), open('2.torrent', 'rb')] qb.download_from_file(torrent_file_list)
指定下载的保存路径:
dl_path = '/home/user/Downloads/special-dir/' qb.download_from_file(myfile, savepath=dl_path) # same for links. qb.download_from_link(my_magnet_uri, savepath=dl_path)
将标签应用于下载:
qb.download_from_file(myfile, label='secret-files ;) ') # same for links. qb.download_from_link(my_magnet_uri, category='anime')
暂停/恢复Torrents
暂停/恢复所有种子:
qb.pause_all() qb.resume_all()
暂停/恢复特定的种子:
info_hash = 'e334ab9ddd....infohash....5d7fff526cb4' qb.pause(info_hash) qb.resume(info_hash)
暂停/恢复多个Torrent:
info_hash_list = ['e334ab9ddd9......infohash......fff526cb4', 'c9dc36f46d9......infohash......90ebebc46', '4c859243615......infohash......8b1f20108'] qb.pause_multiple(info_hash_list) qb.resume_multipe(info_hash_list)
完整的API方法文档
qbittorrent的所有api方法都提到了@Read the docs
待办事项
- 编写测试