00001
00002
00003
00004
00005
00006
00007
00008 #include <boost/python.hpp>
00009 #include <libtorrent/torrent_info.hpp>
00010
00011 using namespace boost::python;
00012 using namespace libtorrent;
00013
00014 namespace
00015 {
00016
00017 std::vector<announce_entry>::const_iterator begin_trackers(torrent_info& i)
00018 {
00019 return i.trackers().begin();
00020 }
00021
00022 std::vector<announce_entry>::const_iterator end_trackers(torrent_info& i)
00023 {
00024 return i.trackers().end();
00025 }
00026
00027 void add_node(torrent_info& ti, char const* hostname, int port)
00028 {
00029 ti.add_node(std::make_pair(hostname, port));
00030 }
00031
00032 list nodes(torrent_info const& ti)
00033 {
00034 list result;
00035
00036 typedef std::vector<std::pair<std::string, int> > list_type;
00037
00038 for (list_type::const_iterator i = ti.nodes().begin(); i != ti.nodes().end(); ++i)
00039 {
00040 result.append(make_tuple(i->first, i->second));
00041 }
00042
00043 return result;
00044 }
00045
00046 }
00047
00048 void bind_torrent_info()
00049 {
00050 return_value_policy<copy_const_reference> copy;
00051
00052 class_<torrent_info>("torrent_info")
00053 .def(init<entry const&>())
00054 .def(init<sha1_hash const&>())
00055
00056 .def("create_torrent", &torrent_info::create_torrent)
00057 .def("set_comment", &torrent_info::set_comment)
00058 .def("set_piece_size", &torrent_info::set_piece_size)
00059 .def("set_creator", &torrent_info::set_creator)
00060 .def("set_hash", &torrent_info::set_hash)
00061 .def("add_tracker", &torrent_info::add_tracker, (arg("url"), arg("tier")=0))
00062 .def("add_file", &torrent_info::add_file)
00063 .def("add_url_seed", &torrent_info::add_url_seed)
00064
00065 .def("name", &torrent_info::name, copy)
00066 .def("comment", &torrent_info::comment, copy)
00067 .def("creator", &torrent_info::creator, copy)
00068 .def("total_size", &torrent_info::total_size)
00069 .def("piece_length", &torrent_info::piece_length)
00070 .def("num_pieces", &torrent_info::num_pieces)
00071 .def("info_hash", &torrent_info::info_hash, copy)
00072
00073 .def("hash_for_piece", &torrent_info::hash_for_piece, copy)
00074 .def("piece_size", &torrent_info::piece_size)
00075
00076 .def("file_at", &torrent_info::file_at, return_internal_reference<>())
00077 .def("files", range(&torrent_info::begin_files, &torrent_info::end_files))
00078
00079 .def("priv", &torrent_info::priv)
00080 .def("set_priv", &torrent_info::set_priv)
00081 .def("trackers", range(begin_trackers, end_trackers))
00082
00083 .def("creation_date", &torrent_info::creation_date)
00084
00085 .def("add_node", &add_node)
00086 .def("nodes", &nodes)
00087 ;
00088
00089 class_<file_entry>("file_entry")
00090 .add_property(
00091 "path"
00092 , make_getter(
00093 &file_entry::path, return_value_policy<copy_non_const_reference>()
00094 )
00095 )
00096 .def_readonly("offset", &file_entry::offset)
00097 .def_readonly("size", &file_entry::size)
00098 ;
00099
00100 class_<announce_entry>("announce_entry", init<std::string const&>())
00101 .def_readwrite("url", &announce_entry::url)
00102 .def_readwrite("tier", &announce_entry::tier)
00103 ;
00104 }
00105