gpt4 book ai didi

c++ - Libtorrent - 给定一个磁力链接,你如何生成一个 torrent 文件?

转载 作者:IT老高 更新时间:2023-10-28 21:03:17 28 4
gpt4 key购买 nike

我已通读 manual我找不到答案。给定一个磁力链接,我想生成一个 torrent 文件,以便在下次启动时加载它,以避免重新下载元数据。我已经尝试过快速恢复功能,但我仍然需要在执行此操作时获取元数据,这可能需要相当长的时间。我看到的示例是为新的 torrent 创建 torrent 文件,而我想创建一个匹配磁铁 uri 的文件。

最佳答案

在这里找到解决方案:

http://code.google.com/p/libtorrent/issues/detail?id=165#c5

查看创建种子:

http://www.rasterbar.com/products/libtorrent/make_torrent.html

修改第一行:

file_storage fs;

// recursively adds files in directories
add_files(fs, "./my_torrent");

create_torrent t(fs);

到这里:

torrent_info ti = handle.get_torrent_info()

create_torrent t(ti)

“句柄”来自这里:

torrent_handle add_magnet_uri(session& ses, std::string const& uri add_torrent_params p);

此外,在创建 torrent 之前,您必须确保已下载元数据,通过调用 handle.has_metadata() 来做到这一点。

更新

似乎 libtorrent python api 缺少一些从磁铁创建 torrent 所需的重要 c++ api,上面的示例在 python 中不起作用,因为 create_torrent python 类不接受 torrent_info 作为参数(c++ 有它可用)。

于是又尝试了另一种方式,但也遇到了砖墙导致无法实现,代码如下:

if handle.has_metadata():

torinfo = handle.get_torrent_info()

fs = libtorrent.file_storage()
for file in torinfo.files():
fs.add_file(file)

torfile = libtorrent.create_torrent(fs)
torfile.set_comment(torinfo.comment())
torfile.set_creator(torinfo.creator())

for i in xrange(0, torinfo.num_pieces()):
hash = torinfo.hash_for_piece(i)
torfile.set_hash(i, hash)

for url_seed in torinfo.url_seeds():
torfile.add_url_seed(url_seed)

for http_seed in torinfo.http_seeds():
torfile.add_http_seed(http_seed)

for node in torinfo.nodes():
torfile.add_node(node)

for tracker in torinfo.trackers():
torfile.add_tracker(tracker)

torfile.set_priv(torinfo.priv())

f = open(magnet_torrent, "wb")
f.write(libtorrent.bencode(torfile.generate()))
f.close()

此行抛出错误:

torfile.set_hash(i, hash)

它期望哈希是 const char*torrent_info.hash_for_piece(int) 返回类 big_number 没有 api 将其转换回来为 const char*。

当我找到时间时,我会向 libtorrent 开发人员报告这个缺失的 api 错误,因为目前使用 python 绑定(bind)时无法从磁铁 uri 创建 .torrent 文件。

torrent_info.orig_files() 在 python 绑定(bind)中也缺少,我不确定 torrent_info.files() 是否足够。

更新 2

我已经为此创建了一个问题,请在此处查看: http://code.google.com/p/libtorrent/issues/detail?id=294

给它加星标,以便他们快速修复它。

更新 3

现在已修复,有 0.16.0 版本。 Windows 的二进制文件也可用。

关于c++ - Libtorrent - 给定一个磁力链接,你如何生成一个 torrent 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8689828/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com