premiere-libtorrent/bindings/python/src/magnet_uri.cpp

86 lines
2.2 KiB
C++
Raw Normal View History

2008-09-09 16:03:35 +02:00
// Copyright Andrew Resch 2008. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
2009-03-02 06:23:25 +01:00
#include <boost/python.hpp>
2008-09-09 16:03:35 +02:00
#include <libtorrent/session.hpp>
#include <libtorrent/torrent.hpp>
#include <libtorrent/magnet_uri.hpp>
#include "gil.hpp"
using namespace boost::python;
using namespace libtorrent;
2014-07-06 21:18:00 +02:00
namespace lt = libtorrent;
2008-09-09 16:03:35 +02:00
2013-08-27 18:04:19 +02:00
extern void dict_to_add_torrent_params(dict params, add_torrent_params& p);
2008-09-09 16:03:35 +02:00
namespace {
#ifndef TORRENT_NO_DEPRECATE
2014-07-06 21:18:00 +02:00
torrent_handle _add_magnet_uri(lt::session& s, std::string uri, dict params)
2008-09-09 16:03:35 +02:00
{
add_torrent_params p;
2013-08-27 18:04:19 +02:00
dict_to_add_torrent_params(params, p);
allow_threading_guard guard;
p.url = uri;
2010-08-22 18:45:12 +02:00
#ifndef BOOST_NO_EXCEPTIONS
return s.add_torrent(p);
2010-08-22 18:45:12 +02:00
#else
error_code ec;
return s.add_torrent(p, ec);
2010-08-22 18:45:12 +02:00
#endif
2008-09-09 16:03:35 +02:00
}
#endif
2013-02-07 03:27:39 +01:00
dict parse_magnet_uri_wrap(std::string const& uri)
{
add_torrent_params p;
error_code ec;
parse_magnet_uri(uri, p, ec);
if (ec) throw libtorrent_exception(ec);
dict ret;
ret["ti"] = p.ti;
list tracker_list;
for (std::vector<std::string>::const_iterator i = p.trackers.begin()
, end(p.trackers.end()); i != end; ++i)
tracker_list.append(*i);
ret["trackers"] = tracker_list;
list nodes_list;
for (std::vector<std::pair<std::string, int> >::const_iterator i = p.dht_nodes.begin()
, end(p.dht_nodes.end()); i != end; ++i)
2014-03-27 08:06:38 +01:00
tracker_list.append(boost::python::make_tuple(i->first, i->second));
2013-02-07 03:27:39 +01:00
ret["dht_nodes"] = nodes_list;
ret["info_hash"] = p.info_hash;
ret["name"] = p.name;
ret["save_path"] = p.save_path;
ret["storage_mode"] = p.storage_mode;
ret["url"] = p.url;
ret["uuid"] = p.uuid;
ret["source_feed_url"] = p.source_feed_url;
ret["flags"] = p.flags;
return ret;
}
std::string (*make_magnet_uri0)(torrent_handle const&) = make_magnet_uri;
std::string (*make_magnet_uri1)(torrent_info const&) = make_magnet_uri;
2008-09-09 16:03:35 +02:00
}
void bind_magnet_uri()
{
#ifndef TORRENT_NO_DEPRECATE
2008-09-09 16:03:35 +02:00
def("add_magnet_uri", &_add_magnet_uri);
#endif
def("make_magnet_uri", make_magnet_uri0);
def("make_magnet_uri", make_magnet_uri1);
2013-02-07 03:27:39 +01:00
def("parse_magnet_uri", parse_magnet_uri_wrap);
2008-09-09 16:03:35 +02:00
}