我试图下载一个仅给出一个.torrent的洪流(特定的.torrent文件)。我知道以前在这里讨论过这个问题,我甚至搜索并相应修改了我的代码。结果如下:
import libtorrent as lt
import time
import sys
import bencode
ses = lt.session()
ses.listen_on(6881, 6891)
params = {
'save_path': '.',
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'duplicate_is_error': True
}
info_hash = "2B3AF3B4977EB5485D39F96FE414729530F48386"
link = "magnet:?xt=urn:btih:" + info_hash
h = lt.add_magnet_uri(ses, link, params)
ses.add_dht_router("router.utorrent.com", 6881)
ses.add_dht_router("router.bittorrent.com", 6881)
ses.add_dht_router("dht.transmissionbt.com", 6881)
ses.start_dht()
while (not h.has_metadata()):
time.sleep(1)
torinfo = h.get_torrent_info()
fs = lt.file_storage()
for f in torinfo.files():
fs.add_file(f)
torfile = lt.create_torrent(fs)
torfile.set_comment(torinfo.comment())
torfile.set_creator(torinfo.creator())
f = open("torrentfile.torrent", "wb")
f.write(lt.bencode(torfile.generate()))
f.close()这会产生一个无法通过传输加载的洪流文件。它既没有跟踪器,也没有真实的片段(创建\x00而不是实际的片段)。
下面的行可以节省碎片,但仍然缺乏跟踪器,无法通过传输打开:
f = open("torrentfile.torrent", "wb")
f.write(lt.bencode(torinfo.metadata()))
f.close()通过使用磁铁链接(如代码中所述),我如何创建一个类似于实际洪流的洪流?
(我使用的是Ubuntu15.04 x64和libtorrent 0.16.18-1)
我不是非法下载文件背后的洪流-然而,我有急流比较,由我的脚本下载的洪流。
发布于 2015-11-28 01:39:53
您没有设置片段散列和( file_storage对象的)块大小。见文档。
但是,创建.torrent文件的一种更简单和更健壮的方法是使用直接接受torrent_info对象的create_torrent构造函数。即:
torfile = lt.create_torrent(h.get_torrent_info())
f = open("torrentfile.torrent", "wb")
f.write(lt.bencode(torfile.generate()))
f.close()https://stackoverflow.com/questions/33936190
复制相似问题