From df459e7eaa3ef47829fd46bce77377e569b46437 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Thu, 1 May 2008 05:37:22 +0000 Subject: [PATCH] Update python bindings to use new add_torrent() method --- libtorrent/bindings/python/src/session.cpp | 51 +++++++++++++------ .../bindings/python/src/torrent_info.cpp | 3 +- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libtorrent/bindings/python/src/session.cpp b/libtorrent/bindings/python/src/session.cpp index a0c60f818..424de0508 100755 --- a/libtorrent/bindings/python/src/session.cpp +++ b/libtorrent/bindings/python/src/session.cpp @@ -97,13 +97,41 @@ namespace allow_threading_guard guard; s.add_extension(invoke_extension_factory(e)); } - - torrent_handle add_torrent(session& s, torrent_info const& ti - , boost::filesystem::path const& save, entry const& resume - , storage_mode_t storage_mode, bool paused) + + torrent_handle add_torrent(session& s, dict params) { - allow_threading_guard guard; - return s.add_torrent(ti, save, resume, storage_mode, paused, default_storage_constructor); + add_torrent_params p; + + if (params.has_key("ti")) + { + boost::intrusive_ptr ti = new torrent_info( + extract(params["ti"])); + p.ti = ti; + } + if (params.has_key("tracker_url")) + { + std::string url = extract(params["tracker_url"]); + p.tracker_url = url.c_str(); + } + if (params.has_key("info_hash")) + { + sha1_hash info_hash = extract(params["info_hash"]); + p.info_hash = info_hash; + } + if (params.has_key("name")) + { + std::string name = extract(params["name"]); + p.name = name.c_str(); + } + p.save_path = fs::path(extract(params["save_path"])); + entry resume = extract(params["resume_data"]); + p.resume_data = &resume; + p.storage_mode = extract(params["storage_mode"]); + p.paused = params["paused"]; + p.auto_managed = params["auto_managed"]; + p.duplicate_is_error = params["duplicate_is_error"]; + + return s.add_torrent(p); } void start_natpmp(session& s) @@ -216,7 +244,7 @@ void bind_session() .value("none", session::none) .value("delete_files", session::delete_files) ; - + class_("session", session_doc, no_init) .def( init(arg("fingerprint")=fingerprint("LT",0,1,0,0), session_init_doc) @@ -240,14 +268,7 @@ void bind_session() .def("dht_state", allow_threads(&session::dht_state), session_dht_state_doc) .def("set_dht_proxy", allow_threads(&session::set_dht_proxy)) #endif - .def( - "add_torrent", &add_torrent - , ( - arg("resume_data") = entry(), arg("storage_mode") = storage_mode_sparse, - arg("paused") = false - ) - , session_add_torrent_doc - ) + .def("add_torrent", &add_torrent, session_add_torrent_doc) .def("remove_torrent", allow_threads(&session::remove_torrent), arg("option") = session::none , session_remove_torrent_doc) .def( diff --git a/libtorrent/bindings/python/src/torrent_info.cpp b/libtorrent/bindings/python/src/torrent_info.cpp index a24ebd181..716ecfdee 100755 --- a/libtorrent/bindings/python/src/torrent_info.cpp +++ b/libtorrent/bindings/python/src/torrent_info.cpp @@ -4,6 +4,7 @@ #include #include +#include "libtorrent/intrusive_ptr_base.hpp" using namespace boost::python; using namespace libtorrent; @@ -69,7 +70,7 @@ void bind_torrent_info() { return_value_policy copy; - class_("torrent_info") + class_ >("torrent_info") .def(init()) .def(init())