非官方的海盗湾轻量级Python API
tpblite的Python项目详细描述
用于piratebay的非官方轻量级Python API
安装
$ pip install tpblite
依赖项:
- lxml公司
使用
^{pr2}$N.B在使用之前,您应该检查哪个piratebay域适合您,因为每个国家的情况不同。
搜索
# Quick search for torrents, returns a Torrents objecttorrents=t.search('public domain')# See how many torrents were foundprint('There were {0} torrents found.'.format(len(torrents)))# Iterate through list of torrents and print info for Torrent objectfortorrentintorrents:print(torrent)# Customize your searchfromtpbliteimportCATEGORIES,ORDERStorrents=t.search('public domain',page=2,order=ORDERS.NAME.DES,category=CATEGORIES.VIDEO.MOVIES)# Get the most seeded torrent based on a filtertorrent=torrents.getBestTorrent(min_seeds=30,min_filesize='500 MiB',max_filesize='4 GiB')# Or select a particular torrent by indexingtorrent=torrents[3]# Get the magnet link for a torrentprint(torrent.magnetlink)
浏览
# You can browse all of the torrents from a single categorytorrents=t.browse(category=CATEGORIES.VIDEO)# Customize the page number and sort ordertorrents=t.browse(category=CATEGORIES.VIDEO.MOVIES,page=1,order=ORDERS.UPLOADED.DES)
顶
fromtpbliteimportTPB,CATEGORIESt=TPB()# Get the top recent torrents torrents=t.top(CATEGORIES.GAMES.ALL)# Customize with category and restriction to torrents from the last 48htorrents=t.top(category=CATEGORIES.GAMES.ALL,last_48=True)
类别和排序顺序
# To print all available categories, use the classmethod printOptionsCATEGORIES.printOptions()# Or just a subset of categories, like VIDEOCATEGORIES.VIDEO.printOptions()# Similarly for the sort orderORDERS.printOptions()
Torrents对象
search函数返回一个Torrents
对象,它是一个list,类似于找到的torrents的集合。在
您还可以通过在for循环中调用Torrents
对象来迭代它(参见上面的示例)。在
通过使用len()
函数,可以看到查询返回了多少Torrent
对象
Torrent对象
Torrent
对象表示在Torrents
类中找到的每个torrent,它们具有以下属性
属性
Torrent.title
-torrent的名称(str)Torrent.seeds
-播种机的数量(int)Torrent.leeches
-leechers数(int)Torrent.upload_date
-上传torrent的日期(str)Torrent.uploader
-上传torrent的用户名称(str)Torrent.filesize
-文件大小为*iB格式,例如5gib(str)Torrent.byte_size
-torrent的文件大小(int)Torrent.magnetlink
-洪流的magnetlink(str)Torrent.url
-torrent页面的URL(str)Torrent.is_trusted
-torrent是否来自可信来源。在Torrent.is_vip
-torrent是否来自VIP源。在
工作流示例
使用命令行torrent客户端,如aria2,您可以自动搜索和下载torrent,如下所示:
importsubprocessfromtpbliteimportTPBt=TPB()torrents=t.search('GIMP 2.10.8')torrent=torrents.getBestTorrent()subprocess.call(['aria2c',torrent.magnetlink])
- 项目
标签: