fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / bindings / python / src / torrent_info.cpp
blob55e7fd6b9cde5cebb227b2b5b4c8ef924198f1a4
1 // Copyright Daniel Wallin 2006. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #include <boost/python.hpp>
6 #include <libtorrent/torrent_info.hpp>
7 #include "libtorrent/intrusive_ptr_base.hpp"
9 using namespace boost::python;
10 using namespace libtorrent;
12 namespace
15 std::vector<announce_entry>::const_iterator begin_trackers(torrent_info& i)
17 return i.trackers().begin();
20 std::vector<announce_entry>::const_iterator end_trackers(torrent_info& i)
22 return i.trackers().end();
25 void add_node(torrent_info& ti, char const* hostname, int port)
27 ti.add_node(std::make_pair(hostname, port));
30 list nodes(torrent_info const& ti)
32 list result;
34 typedef std::vector<std::pair<std::string, int> > list_type;
36 for (list_type::const_iterator i = ti.nodes().begin(); i != ti.nodes().end(); ++i)
38 result.append(make_tuple(i->first, i->second));
41 return result;
44 file_storage::iterator begin_files(torrent_info& i)
46 return i.begin_files();
49 file_storage::iterator end_files(torrent_info& i)
51 return i.end_files();
54 //list files(torrent_info const& ti, bool storage) {
55 list files(torrent_info const& ti, bool storage) {
56 list result;
58 typedef std::vector<file_entry> list_type;
60 for (list_type::const_iterator i = ti.begin_files(); i != ti.end_files(); ++i)
61 result.append(*i);
63 return result;
67 } // namespace unnamed
69 void bind_torrent_info()
71 return_value_policy<copy_const_reference> copy;
73 class_<torrent_info, boost::intrusive_ptr<torrent_info> >("torrent_info", no_init)
74 .def(init<entry const&>())
75 .def(init<sha1_hash const&>())
76 .def(init<char const*, int>())
77 .def(init<char const*>())
79 .def("add_tracker", &torrent_info::add_tracker, (arg("url"), arg("tier")=0))
80 .def("add_url_seed", &torrent_info::add_url_seed)
82 .def("name", &torrent_info::name, copy)
83 .def("comment", &torrent_info::comment, copy)
84 .def("creator", &torrent_info::creator, copy)
85 .def("total_size", &torrent_info::total_size)
86 .def("piece_length", &torrent_info::piece_length)
87 .def("num_pieces", &torrent_info::num_pieces)
88 .def("info_hash", &torrent_info::info_hash, copy)
90 .def("hash_for_piece", &torrent_info::hash_for_piece)
91 .def("piece_size", &torrent_info::piece_size)
93 .def("num_files", &torrent_info::num_files, (arg("storage")=false))
94 .def("file_at", &torrent_info::file_at, return_internal_reference<>())
95 .def("files", &files, (arg("storage")=false))
97 .def("priv", &torrent_info::priv)
98 .def("trackers", range(begin_trackers, end_trackers))
100 .def("creation_date", &torrent_info::creation_date)
102 .def("add_node", &add_node)
103 .def("nodes", &nodes)
106 class_<file_entry>("file_entry")
107 .add_property(
108 "path"
109 , make_getter(
110 &file_entry::path, return_value_policy<copy_non_const_reference>()
113 .def_readonly("offset", &file_entry::offset)
114 .def_readonly("size", &file_entry::size)
117 class_<announce_entry>("announce_entry", init<std::string const&>())
118 .def_readwrite("url", &announce_entry::url)
119 .def_readwrite("tier", &announce_entry::tier)