在这里找到解决方案:
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)
它期望 hash 为 const char* 但 torrent_info.hash_for_piece(int) 返回类 big_number 没有 api 将其转换回 const char*。
当我找到时间时,我会向 libtorrent 开发人员报告这个缺失的 api 错误,因为目前在使用 python 绑定时无法从磁铁 uri 创建 .torrent 文件。
torrent_info.orig_files() 也缺少在 python 绑定中,我不确定torrent_info.files() 是否足够。
更新 2
我已经为此创建了一个问题,请在此处查看:
http://code.google.com/p/libtorrent/issues/detail?id=294
给它加星标,以便他们快速修复它。
更新 3
现在已修复,有一个 0.16.0 版本。 Windows 的二进制文件也可用。