问题描述
也许我误解了.torrent文件的工作方式,但是python中是否有一种方法可以下载实际引用的内容.作为utorrent,但使用python在shell/命令行中进行?
Perhaps I'm misunderstanding how .torrent files work, but is there a way in python to download the actual referenced content the .torrent file points to that would be downloaded say using a torrent client such as utorrent, but from the shell/command line using python?
以下仅用于下载.torrent文件并确保我也可以打开torrent客户端的方法确实可以下载.torrent,但是我宁愿在命令行中简化该过程.似乎在网上找不到太多有关此操作的信息...
The following works for simply downloading a .torrent file and sure I could open the torrent client as well do download the .torrent, but I'd rather streamline the process in the command line. Can't seem to find much online about doing this...
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用于python3.
As far as I know i can't use libtorrent for python3 on a 64 bit windows os.
推荐答案
如果 magnet:
链接在网络浏览器中工作,然后从Python脚本开始新的torrent下载的一种简单方法是使用网络浏览器打开网址:
If magnet:
links work in your web browser then a simple way to start a new torrent download from your Python script is to open the url using your web browser:
import webbrowser
webbrowser.open(magnet_link)
或通过命令行:
$ python -m webbrowser "magnet:?xt=urn:btih:ebab37b86830e1ed624c1fdbb2c59a1800135610&dn=StackOverflow201508.7z"
下载由您的实际洪流客户端(例如uTorrent)执行.
The download is performed by your actual torrent client such as uTorrent.
这篇关于下载内容torrent文件指向python3中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!