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
|
|
|
|
|
2016-04-08 04:45:23 +02: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);
|
2011-11-08 06:36:22 +01:00
|
|
|
|
2008-09-09 16:03:35 +02:00
|
|
|
namespace {
|
2012-06-14 17:41:39 +02:00
|
|
|
|
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2016-04-08 04:45:23 +02:00
|
|
|
torrent_handle _add_magnet_uri(lt::session& s, std::string uri, dict params)
|
|
|
|
{
|
|
|
|
add_torrent_params p;
|
2008-09-09 16:03:35 +02:00
|
|
|
|
2016-04-08 04:45:23 +02:00
|
|
|
dict_to_add_torrent_params(params, p);
|
2011-11-08 06:36:22 +01:00
|
|
|
|
2016-04-08 04:45:23 +02:00
|
|
|
allow_threading_guard guard;
|
2011-11-29 12:12:11 +01:00
|
|
|
|
2016-04-08 04:45:23 +02:00
|
|
|
p.url = uri;
|
2014-07-05 16:10:25 +02:00
|
|
|
|
2010-08-22 18:45:12 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2016-04-08 04:45:23 +02:00
|
|
|
return s.add_torrent(p);
|
2010-08-22 18:45:12 +02:00
|
|
|
#else
|
2016-04-08 04:45:23 +02:00
|
|
|
error_code ec;
|
|
|
|
return s.add_torrent(p, ec);
|
2010-08-22 18:45:12 +02:00
|
|
|
#endif
|
2016-04-08 04:45:23 +02:00
|
|
|
}
|
2012-06-14 17:41:39 +02:00
|
|
|
#endif
|
2011-11-16 07:12:48 +01:00
|
|
|
|
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;
|
2016-02-20 21:49:49 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2013-02-07 03:27:39 +01:00
|
|
|
ret["uuid"] = p.uuid;
|
2016-02-20 21:49:49 +01:00
|
|
|
#endif
|
2013-02-07 03:27:39 +01:00
|
|
|
ret["flags"] = p.flags;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-16 07:12:48 +01:00
|
|
|
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()
|
|
|
|
{
|
2012-06-14 17:41:39 +02:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2016-04-08 04:45:23 +02:00
|
|
|
def("add_magnet_uri", &_add_magnet_uri);
|
2012-06-14 17:41:39 +02:00
|
|
|
#endif
|
2016-04-08 04:45:23 +02:00
|
|
|
def("make_magnet_uri", make_magnet_uri0);
|
|
|
|
def("make_magnet_uri", make_magnet_uri1);
|
|
|
|
def("parse_magnet_uri", parse_magnet_uri_wrap);
|
2008-09-09 16:03:35 +02:00
|
|
|
}
|
2011-11-16 07:12:48 +01:00
|
|
|
|