c++ - Libtorrent 洪流->磁铁

标签 c++ torrent libtorrent

我正在尝试使用 libtorrent 将一些种子文件转换为磁铁。

我读过你可以在 python 中使用

 info = libtorrent.torrent_info(sys.argv[1])
 print "magnet:?xt=urn:btih:%s&dn=%s" % (info.info_hash(), info.name())

我已经在 C++ 上尝试了以下内容

 torrent_info ti(current_file.c_str(), ec);
 printf("magnet:?xt=urn:btih:%s&dn=%s\n", ti.info_hash().to_string().c_str(), ti.name().c_str());

但是结果不是正确的字符串(是二进制的)并且不能使用结果。

有人知道如何将 torrent 的哈希值转换成我可以打印的东西吗?

非常感谢。

最佳答案

您可以使用 "libtorrent/magnet_uri.hpp" 中声明的 make_magnet_uri

这是将 torrent 文件转换为磁力 uri 的示例代码:

error_code ec;
torrent_info ti("filename", ec);
std::string magnet_uri = make_magnet_uri(ti);

关于c++ - Libtorrent 洪流->磁铁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44134078/

相关文章:

c++ - 在保留 GL 上下文的同时删除 SDL2 窗口

c++ - extern 模板不适用于 gcc?

c++ - 为什么我的质量计算器不能正确处理空格?

protocols - Torrent 握手响应大于 68 字节

c++ - 如何防止 libtorrent 创建具有名称的文件夹?

python - 使用 apt-get 将软件包安装到虚拟环境中

libtorrent-rasterbar 的 Python 绑定(bind)不起作用

c++ - 如何迭代这个 map ?

java - 将 DHT 和 Torrent Client 拼接在一起

php - 传输php类错误