1
votes

I'm trying to convert some torrents into magnets using libtorrent.

I've read that in python you can use

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

I've tried the following on 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());

But the result is not a proper string (is binary) and cannot use the result.

Someone knows how to convert the hash of a torrent to something I can print?

Thanks a lot.

1

1 Answers

0
votes

You can use make_magnet_uri declared in "libtorrent/magnet_uri.hpp".

Here's a sample code to convert torrent file to magnet uri:

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