python libtorrent 如何从 info_hash 获取 torrent 文件列表?

Posted

技术标签:

【中文标题】python libtorrent 如何从 info_hash 获取 torrent 文件列表?【英文标题】:python libtorrent How I get file list of torrent from info_hash? 【发布时间】:2014-11-23 04:20:41 【问题描述】: def magnet2torrent(id, info_hash): info_hash_id=id 磁铁="磁铁:?xt=urn:btih:"+info_hash ses = lt.session() 参数 = 'save_path': './', 'duplicate_is_error':是的, 'storage_mode': lt.storage_mode_t(2), “暂停”:错误, 'auto_managed':是的, 'duplicate_is_error':真 句柄 = lt.add_magnet_uri(ses, 磁铁, 参数) print("正在下载元数据(这可能需要一段时间)") 我 = 0; 而(不是handle.has_metadata()): # i = i+1 如果我 > 300 : 返回 睡觉(1) ses.pause() 打印(“完成”) torinfo = handle.get_torrent_info() con = db.get_conncetion() cur = con.cursor() 对于 torinfo 中的 f: cur.execute("INSERT INTO file_list (info_hash_id, name, size) VALUES (\""+str(info_hash_id)+"\", \""+str(f.path)+"\", "+str(f .size)+");") print("INSERT INTO file_list (info_hash_id, name, size) 值 (\""+str(info_hash_id)+"\", \""+str(f.path)+"\", "+str(f.size )+");") con.commit() cur.close() con.close()

我想如果我可以从 info_hash 中获取 torrent 文件,那么我可以从 torrent 文件中获取文件列表。

但是当我运行我的代码时

while (not handle.has_metadata()):
没有结束。 但是像http://magnet2torrent.com这样的网页立即给我torrent

如何从 info_hash 中获取文件列表?

【问题讨论】:

【参考方案1】:

如果您的磁力链接中没有任何跟踪器,则需要启动 DHT。你可以通过调用来做到这一点:

ses.add_dht_router("router.utorrent.com", 6881)
ses.start_dht()

在构造会话对象之后。

【讨论】:

我添加了类似
 magnet="magnet:?xt=urn:btih:"+info_hash ses = lt.session() ses.add_dht_router("router.utorrent.com", 6881)ses.start_dht()参数= 'save_path':'./','duplicate_is_error':真,'storage_mode':lt.storage_mode_t(2),'暂停':假,'auto_managed':真,'duplicate_is_error ': True  handle = lt.add_magnet_uri(ses, magnet, params)
但循环未结束
你有没有找到任何同行?你最终在 DHT 路由表中有任何节点吗?

以上是关于python libtorrent 如何从 info_hash 获取 torrent 文件列表?的主要内容,如果未能解决你的问题,请参考以下文章

Libtorrent,Python,如何设置下载速度

使用 python-libtorrent 从 torrent 文件中获取 torrent 下载目录

如何使用 python-libtorrent 获取 torrent 的对等列表?

如何使用 libtorrent 下载完全跳过将文件写入磁盘?

如何在python中使用libtorrent的udp协议跟踪器协议

libtorrent-rasterbar 的 Python 绑定不起作用