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

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/lazy_entry.hpp"
#include "libtorrent/magnet_uri.hpp"
#include <boost/filesystem/operations.hpp>
@ -105,6 +106,7 @@ int main(int argc, char* argv[])
std::cout << "info hash: " << t.info_hash() << "\n";
std::cout << "comment: " << t.comment() << "\n";
std::cout << "created by: " << t.creator() << "\n";
std::cout << "magnet link: " << make_magnet_uri(t) << "\n";
std::cout << "files:\n";
int index = 0;
for (torrent_info::file_iterator i = t.begin_files();

View File

@ -46,6 +46,7 @@ namespace libtorrent
struct torrent_handle;
std::string TORRENT_EXPORT make_magnet_uri(torrent_handle const& handle);
std::string TORRENT_EXPORT make_magnet_uri(torrent_info const& info);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 0.14

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