下载python3中指向的内容torrent文件

2024-05-12 16:41:39 发布

您现在位置:Python中文网/ 问答频道 /正文

也许我误解了.torrent文件是如何工作的,但是在python中有没有一种方法可以下载实际引用的内容。torrent文件指向将要下载的内容,比如使用像utorrent这样的torrent客户机,而是使用python从shell/命令行下载?在

下面的方法只需下载一个.torrent文件,我可以打开torrent客户机,也可以下载.torrent,但我宁愿在命令行中简化这个过程。在网上找不到什么。。。在

torrent = torrentutils.parse_magnet(magnet)
infohash = torrent['infoHash']
session = requests.Session()
session.headers.update({'User-Agent': 'Mozilla/5.0'})
url = "http://torcache.net/torrent/" + infohash + ".torrent"
answer = session.get(url)
torrent_data = answer.content
buffer = BytesIO(torrent_data)
gz = gzip.GzipFile(fileobj = buffer)
output = open(torrent['name'], "wb")
output.write(torrent_data)

据我所知,我不能在64位windows操作系统上使用libtorrent for python3。在


Tags: 文件方法命令行answerurl内容outputdata
2条回答

BitTornado可在Windows上运行,并具有命令行界面。看看btdownloadheadless.py. 但这是用python2编写的。 http://www.bittornado.com/download.html

如果^{} links可以在web浏览器中使用,那么从Python脚本开始新torrent下载的一个简单方法是使用web浏览器打开url:

import webbrowser

webbrowser.open(magnet_link)

或从命令行:

^{pr2}$

下载由您实际的torrent客户端(如uTorrent)执行。在

相关问题 更多 >