【问题标题】:download content torrent files point to in python3下载内容torrent文件指向python3
【发布时间】:2015-11-25 02:34:19
【问题描述】:

也许我误解了 .torrent 文件的工作原理,但是在 python 中是否有办法下载实际引用的 content .torrent 文件指向的文件将使用 torrent 客户端下载,例如作为 utorrent,但从 shell/命令行使用 python?

以下内容仅用于下载 .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。

【问题讨论】:

  • 然后使用 32 位 python - python3 win32 有官方构建的 libtorrent 包。是的,x64-package 没有维护者,但您可以尝试自己构建它。

标签: python python-3.x bittorrent libtorrent


【解决方案1】:

如果magnet: links 在您的网络浏览器中工作,那么从您的 Python 脚本开始新的 torrent 下载的一种简单方法是使用您的网络浏览器打开 URL:

import webbrowser

webbrowser.open(magnet_link)

或者从命令行:

$ python -m webbrowser "magnet:?xt=urn:btih:ebab37b86830e1ed624c1fdbb2c59a1800135610&dn=StackOverflow201508.7z"

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-03
      • 2012-04-09
      相关资源
      最近更新 更多