非官方的海盗湾轻量级Python API

tpblite的Python项目详细描述


用于piratebay的非官方轻量级Python API

Build StatusCoverage StatusPyPI version

安装

$ 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])

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

推荐PyPI第三方库


热门话题
java如何在Android Wifi中筛选相同的SSID?   Java中重写接口中异常处理的泛型   java“无效转义序列(有效的是\b\t\n\f\r\”\“\”\)”语法错误   使用JNDI的java NameReadyBoundException   java如何在这个程序上执行算法   java为什么我的应用程序在调试时崩溃而应用程序停止?   Java:while循环未检测到中断条件,但如果块检测到   java如何快速使用jfreechart创建的折线图   java将输入放入JSTL会话变量,以便稍后在屏幕上显示   java在spring boot中加载外部JAR   java Apache NiFi无法使用ojdbc6连接到Oracle 12c。jar或ojdbc8。罐子   java解释StringToWordVector()Weka的输出   java charAt()找不到符号   使用mpjexpress的java阅读控制台输入