made dump torrent create magnet links

This commit is contained in:
Arvid Norberg
2008-08-27 18:44:35 +00:00
parent 9c59d1a308
commit 9b38724417
3 changed files with 23 additions and 0 deletions

View File

@@ -69,6 +69,26 @@ namespace libtorrent
return ret.str();
}
std::string make_magnet_uri(torrent_info const& info)
{
std::stringstream ret;
if (!info.is_valid()) return ret.str();
std::string name = info.name();
ret << "magnet:?xt=urn:btih:" << base32encode(
std::string((char*)info.info_hash().begin(), 20));
if (!name.empty())
ret << "&dn=" << escape_string(name.c_str(), name.length());
std::vector<announce_entry> const& tr = info.trackers();
if (!tr.empty())
{
ret << "&tr=" << escape_string(tr[0].url.c_str()
, tr[0].url.length());
}
return ret.str();
}
#ifndef TORRENT_NO_DEPRECATE
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, fs::path const& save_path