00001
00002
00003
00004
00005
00006
00007
00008 #include <libtorrent/torrent_handle.hpp>
00009 #include <boost/python.hpp>
00010 #include "gil.hpp"
00011
00012 using namespace boost::python;
00013 using namespace libtorrent;
00014
00015 namespace
00016 {
00017
00018 std::vector<announce_entry>::const_iterator begin_trackers(torrent_handle& i)
00019 {
00020 allow_threading_guard guard;
00021 return i.trackers().begin();
00022 }
00023
00024 std::vector<announce_entry>::const_iterator end_trackers(torrent_handle& i)
00025 {
00026 allow_threading_guard guard;
00027 return i.trackers().end();
00028 }
00029
00030 }
00031
00032 list file_progress(torrent_handle& handle)
00033 {
00034 std::vector<float> p;
00035
00036 {
00037 allow_threading_guard guard;
00038 p.reserve(handle.get_torrent_info().num_files());
00039 handle.file_progress(p);
00040 }
00041
00042 list result;
00043
00044 for (std::vector<float>::iterator i(p.begin()), e(p.end()); i != e; ++i)
00045 result.append(*i);
00046
00047 return result;
00048 }
00049
00050 list get_peer_info(torrent_handle const& handle)
00051 {
00052 std::vector<peer_info> pi;
00053
00054 {
00055 allow_threading_guard guard;
00056 handle.get_peer_info(pi);
00057 }
00058
00059 list result;
00060
00061 for (std::vector<peer_info>::iterator i = pi.begin(); i != pi.end(); ++i)
00062 {
00063 result.append(*i);
00064 }
00065
00066 return result;
00067 }
00068
00069 void replace_trackers(torrent_handle& info, object trackers)
00070 {
00071 object iter(trackers.attr("__iter__")());
00072
00073 std::vector<announce_entry> result;
00074
00075 for (;;)
00076 {
00077 handle<> entry(allow_null(PyIter_Next(iter.ptr())));
00078
00079 if (entry == handle<>())
00080 break;
00081
00082 result.push_back(extract<announce_entry const&>(object(entry)));
00083 }
00084
00085 allow_threading_guard guard;
00086 info.replace_trackers(result);
00087 }
00088
00089 void bind_torrent_handle()
00090 {
00091 void (torrent_handle::*force_reannounce0)() const = &torrent_handle::force_reannounce;
00092 void (torrent_handle::*force_reannounce1)(boost::posix_time::time_duration) const
00093 = &torrent_handle::force_reannounce;
00094
00095 return_value_policy<copy_const_reference> copy;
00096
00097 #define _ allow_threads
00098
00099 class_<torrent_handle>("torrent_handle")
00100 .def("status", _(&torrent_handle::status))
00101 .def("torrent_info", _(&torrent_handle::get_torrent_info), return_internal_reference<>())
00102 .def("is_valid", _(&torrent_handle::is_valid))
00103 .def("write_resume_data", _(&torrent_handle::write_resume_data))
00104 .def("force_reannounce", _(force_reannounce0))
00105 .def("force_reannounce", _(force_reannounce1))
00106 .def("set_tracker_login", _(&torrent_handle::set_tracker_login))
00107 .def("add_url_seed", _(&torrent_handle::add_url_seed))
00108 .def("set_ratio", _(&torrent_handle::set_ratio))
00109 .def("set_max_uploads", _(&torrent_handle::set_max_uploads))
00110 .def("set_max_connections", _(&torrent_handle::set_max_connections))
00111 .def("set_upload_limit", _(&torrent_handle::set_upload_limit))
00112 .def("set_download_limit", _(&torrent_handle::set_download_limit))
00113 .def("set_sequenced_download_threshold", _(&torrent_handle::set_sequenced_download_threshold))
00114 .def("pause", _(&torrent_handle::pause))
00115 .def("resume", _(&torrent_handle::resume))
00116 .def("is_paused", _(&torrent_handle::is_paused))
00117 .def("is_seed", _(&torrent_handle::is_seed))
00118 .def("filter_piece", _(&torrent_handle::filter_piece))
00119 .def("is_piece_filtered", _(&torrent_handle::is_piece_filtered))
00120 .def("has_metadata", _(&torrent_handle::has_metadata))
00121 .def("save_path", _(&torrent_handle::save_path))
00122 .def("move_storage", _(&torrent_handle::move_storage))
00123 .def("info_hash", _(&torrent_handle::info_hash), copy)
00124 .def("file_progress", file_progress)
00125 .def("trackers", range(begin_trackers, end_trackers))
00126 .def("replace_trackers", replace_trackers)
00127 .def("get_peer_info", get_peer_info)
00128 ;
00129 }
00130