2007-01-10 17:11:43 +01:00
|
|
|
// Copyright Daniel Wallin 2006. Use, modification and distribution is
|
|
|
|
// subject to the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <libtorrent/torrent_info.hpp>
|
2008-05-01 07:37:04 +02:00
|
|
|
#include "libtorrent/intrusive_ptr_base.hpp"
|
2007-01-10 17:11:43 +01:00
|
|
|
|
|
|
|
using namespace boost::python;
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
std::vector<announce_entry>::const_iterator begin_trackers(torrent_info& i)
|
|
|
|
{
|
|
|
|
return i.trackers().begin();
|
|
|
|
}
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
std::vector<announce_entry>::const_iterator end_trackers(torrent_info& i)
|
|
|
|
{
|
|
|
|
return i.trackers().end();
|
|
|
|
}
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
void add_node(torrent_info& ti, char const* hostname, int port)
|
|
|
|
{
|
|
|
|
ti.add_node(std::make_pair(hostname, port));
|
|
|
|
}
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
list nodes(torrent_info const& ti)
|
|
|
|
{
|
|
|
|
list result;
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
typedef std::vector<std::pair<std::string, int> > list_type;
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
for (list_type::const_iterator i = ti.nodes().begin(); i != ti.nodes().end(); ++i)
|
|
|
|
{
|
|
|
|
result.append(make_tuple(i->first, i->second));
|
|
|
|
}
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
return result;
|
|
|
|
}
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
file_storage::iterator begin_files(torrent_info& i)
|
|
|
|
{
|
|
|
|
return i.begin_files();
|
|
|
|
}
|
2008-03-28 22:37:35 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
file_storage::iterator end_files(torrent_info& i)
|
|
|
|
{
|
|
|
|
return i.end_files();
|
|
|
|
}
|
2008-03-28 22:37:35 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
//list files(torrent_info const& ti, bool storage) {
|
|
|
|
list files(torrent_info const& ti, bool storage) {
|
|
|
|
list result;
|
2007-08-27 12:31:35 +02:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
typedef std::vector<file_entry> list_type;
|
2007-08-27 12:31:35 +02:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
for (list_type::const_iterator i = ti.begin_files(); i != ti.end_files(); ++i)
|
|
|
|
result.append(*i);
|
2008-03-28 22:37:35 +01:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
return result;
|
|
|
|
}
|
2007-08-27 12:31:35 +02:00
|
|
|
|
2008-09-30 20:41:43 +02:00
|
|
|
std::string metadata(torrent_info const& ti) {
|
|
|
|
std::string result(ti.metadata().get(), ti.metadata_size());
|
|
|
|
return result;
|
|
|
|
}
|
2008-10-28 07:29:30 +01:00
|
|
|
|
|
|
|
torrent_info construct0(std::string path) {
|
2009-10-26 02:29:39 +01:00
|
|
|
return torrent_info(path);
|
2008-10-28 07:29:30 +01:00
|
|
|
}
|
2008-12-14 21:51:22 +01:00
|
|
|
|
|
|
|
list map_block(torrent_info& ti, int piece, size_type offset, int size)
|
|
|
|
{
|
|
|
|
std::vector<file_slice> p = ti.map_block(piece, offset, size);
|
|
|
|
list result;
|
|
|
|
|
|
|
|
for (std::vector<file_slice>::iterator i(p.begin()), e(p.end()); i != e; ++i)
|
|
|
|
result.append(*i);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-01-10 17:11:43 +01:00
|
|
|
} // namespace unnamed
|
|
|
|
|
|
|
|
void bind_torrent_info()
|
|
|
|
{
|
|
|
|
return_value_policy<copy_const_reference> copy;
|
|
|
|
|
2009-07-16 09:10:58 +02:00
|
|
|
void (torrent_info::*rename_file0)(int, std::string const&) = &torrent_info::rename_file;
|
|
|
|
#ifndef BOOST_FILESYSTEM_NARROW_ONLY
|
|
|
|
void (torrent_info::*rename_file1)(int, std::wstring const&) = &torrent_info::rename_file;
|
|
|
|
#endif
|
|
|
|
|
2008-12-14 21:51:22 +01:00
|
|
|
class_<file_slice>("file_slice")
|
|
|
|
.def_readwrite("file_index", &file_slice::file_index)
|
|
|
|
.def_readwrite("offset", &file_slice::offset)
|
|
|
|
.def_readwrite("size", &file_slice::size)
|
|
|
|
;
|
|
|
|
|
2008-06-02 19:39:11 +02:00
|
|
|
class_<torrent_info, boost::intrusive_ptr<torrent_info> >("torrent_info", no_init)
|
2008-10-28 07:29:30 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2007-01-10 17:11:43 +01:00
|
|
|
.def(init<entry const&>())
|
2008-10-28 07:29:30 +01:00
|
|
|
#endif
|
2007-01-10 17:11:43 +01:00
|
|
|
.def(init<sha1_hash const&>())
|
2008-06-02 19:39:11 +02:00
|
|
|
.def(init<char const*, int>())
|
2009-10-26 02:29:39 +01:00
|
|
|
.def(init<std::string>())
|
|
|
|
.def(init<std::wstring>())
|
2008-10-28 07:29:30 +01:00
|
|
|
|
2007-01-10 17:11:43 +01:00
|
|
|
.def("add_tracker", &torrent_info::add_tracker, (arg("url"), arg("tier")=0))
|
|
|
|
.def("add_url_seed", &torrent_info::add_url_seed)
|
|
|
|
|
|
|
|
.def("name", &torrent_info::name, copy)
|
|
|
|
.def("comment", &torrent_info::comment, copy)
|
|
|
|
.def("creator", &torrent_info::creator, copy)
|
|
|
|
.def("total_size", &torrent_info::total_size)
|
|
|
|
.def("piece_length", &torrent_info::piece_length)
|
|
|
|
.def("num_pieces", &torrent_info::num_pieces)
|
2008-10-28 07:29:30 +01:00
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
2007-01-10 17:11:43 +01:00
|
|
|
.def("info_hash", &torrent_info::info_hash, copy)
|
2008-10-28 07:29:30 +01:00
|
|
|
#endif
|
2008-05-15 09:47:36 +02:00
|
|
|
.def("hash_for_piece", &torrent_info::hash_for_piece)
|
2007-01-10 17:11:43 +01:00
|
|
|
.def("piece_size", &torrent_info::piece_size)
|
2008-03-28 22:37:35 +01:00
|
|
|
|
|
|
|
.def("num_files", &torrent_info::num_files, (arg("storage")=false))
|
2007-01-10 17:11:43 +01:00
|
|
|
.def("file_at", &torrent_info::file_at, return_internal_reference<>())
|
2008-12-14 21:51:22 +01:00
|
|
|
.def("file_at_offset", &torrent_info::file_at_offset)
|
2007-08-27 12:31:35 +02:00
|
|
|
.def("files", &files, (arg("storage")=false))
|
2009-07-16 09:10:58 +02:00
|
|
|
.def("rename_file", rename_file0)
|
|
|
|
#ifndef BOOST_FILESYSTEM_NARROW_ONLY
|
|
|
|
.def("rename_file", rename_file1)
|
|
|
|
#endif
|
2007-01-10 17:11:43 +01:00
|
|
|
|
|
|
|
.def("priv", &torrent_info::priv)
|
|
|
|
.def("trackers", range(begin_trackers, end_trackers))
|
|
|
|
|
|
|
|
.def("creation_date", &torrent_info::creation_date)
|
|
|
|
|
|
|
|
.def("add_node", &add_node)
|
|
|
|
.def("nodes", &nodes)
|
2008-09-30 20:41:43 +02:00
|
|
|
.def("metadata", &metadata)
|
|
|
|
.def("metadata_size", &torrent_info::metadata_size)
|
2008-12-14 21:51:22 +01:00
|
|
|
.def("map_block", map_block)
|
|
|
|
.def("map_file", &torrent_info::map_file)
|
2007-01-10 17:11:43 +01:00
|
|
|
;
|
2008-03-28 22:37:35 +01:00
|
|
|
|
2007-01-10 17:11:43 +01:00
|
|
|
class_<file_entry>("file_entry")
|
2007-08-27 12:31:35 +02:00
|
|
|
.add_property(
|
2007-01-10 17:11:43 +01:00
|
|
|
"path"
|
|
|
|
, make_getter(
|
|
|
|
&file_entry::path, return_value_policy<copy_non_const_reference>()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.def_readonly("offset", &file_entry::offset)
|
|
|
|
.def_readonly("size", &file_entry::size)
|
2009-02-21 09:39:26 +01:00
|
|
|
.def_readonly("file_base", &file_entry::file_base)
|
2007-01-10 17:11:43 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
class_<announce_entry>("announce_entry", init<std::string const&>())
|
|
|
|
.def_readwrite("url", &announce_entry::url)
|
|
|
|
.def_readwrite("tier", &announce_entry::tier)
|
|
|
|
;
|
|
|
|
}
|