From c9d9371065295878b80eb776cce762e563a65f3f Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 15 Feb 2019 13:55:21 +0100 Subject: [PATCH] add missing get_torrent_status() and refresh_torrent_status() to python binding --- bindings/python/src/session.cpp | 39 +++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 1c2969ec5..283b53155 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #ifndef TORRENT_NO_DEPRECATE #include @@ -469,17 +470,49 @@ namespace list get_torrents(lt::session& s) { - list ret; std::vector torrents; { allow_threading_guard guard; torrents = s.get_torrents(); } + list ret; for (std::vector::iterator i = torrents.begin(); i != torrents.end(); ++i) - { ret.append(*i); + return ret; + } + + bool wrap_pred(object pred, torrent_status const& st) + { + return pred(st); + } + + list get_torrent_status(lt::session& s, object pred, int const flags) + { + std::vector torrents; + s.get_torrent_status(&torrents, boost::bind(&wrap_pred, pred, _1), flags); + + list ret; + for (std::vector::iterator i = torrents.begin(); i != torrents.end(); ++i) + ret.append(*i); + return ret; + } + + list refresh_torrent_status(lt::session& s, list in_torrents, int const flags) + { + std::vector torrents; + int const n = boost::python::len(in_torrents); + for (int i = 0; i < n; ++i) + torrents.push_back(extract(in_torrents[i])); + + { + allow_threading_guard guard; + s.refresh_torrent_status(&torrents, flags); } + + list ret; + for (std::vector::iterator i = torrents.begin(); i != torrents.end(); ++i) + ret.append(*i); return ret; } @@ -972,6 +1005,8 @@ void bind_session() .def("get_ip_filter", allow_threads(<::session::get_ip_filter)) .def("find_torrent", allow_threads(<::session::find_torrent)) .def("get_torrents", &get_torrents) + .def("get_torrent_status", &get_torrent_status, (arg("session"), arg("pred"), arg("flags") = 0)) + .def("refresh_torrent_status", &refresh_torrent_status, (arg("session"), arg("torrents"), arg("flags") = 0)) .def("pause", allow_threads(<::session::pause)) .def("resume", allow_threads(<::session::resume)) .def("is_paused", allow_threads(<::session::is_paused))