2009-02-21 09:39:26 +01:00
|
|
|
// Copyright Daniel Wallin & Arvid Norberg 2009. 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/create_torrent.hpp>
|
|
|
|
#include <libtorrent/file_storage.hpp>
|
|
|
|
#include "libtorrent/intrusive_ptr_base.hpp"
|
|
|
|
|
|
|
|
using namespace boost::python;
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
2009-08-28 05:46:19 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void set_hash(create_torrent& c, int p, char const* hash)
|
|
|
|
{
|
|
|
|
c.set_hash(p, sha1_hash(hash));
|
|
|
|
}
|
2009-10-02 03:26:31 +02:00
|
|
|
|
|
|
|
void call_python_object(boost::python::object const& obj, int i)
|
|
|
|
{
|
|
|
|
obj(i);
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:45:12 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2009-10-26 02:29:39 +01:00
|
|
|
void set_piece_hashes_callback(create_torrent& c, std::string const& p
|
2009-10-02 03:26:31 +02:00
|
|
|
, boost::python::object cb)
|
|
|
|
{
|
|
|
|
set_piece_hashes(c, p, boost::bind(call_python_object, cb, _1));
|
|
|
|
}
|
2010-08-22 18:45:12 +02:00
|
|
|
#else
|
|
|
|
void set_piece_hashes_callback(create_torrent& c, std::string const& p
|
|
|
|
, boost::python::object cb)
|
|
|
|
{
|
|
|
|
error_code ec;
|
|
|
|
set_piece_hashes(c, p, boost::bind(call_python_object, cb, _1), ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_piece_hashes0(create_torrent& c, std::string const & s)
|
|
|
|
{
|
|
|
|
error_code ec;
|
|
|
|
set_piece_hashes(c, s, ec);
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-22 10:21:40 +02:00
|
|
|
|
|
|
|
void add_node(create_torrent& ct, std::string const& addr, int port)
|
|
|
|
{
|
|
|
|
ct.add_node(std::make_pair(addr, port));
|
|
|
|
}
|
2010-11-15 06:10:36 +01:00
|
|
|
|
|
|
|
void add_file(file_storage& ct, file_entry const& fe
|
|
|
|
, std::string const& hash, std::string const& linkpath)
|
|
|
|
{
|
|
|
|
ct.add_file(fe, hash.empty() ? 0 : &sha1_hash(hash)
|
|
|
|
, linkpath.empty() ? 0 : &linkpath);
|
|
|
|
}
|
2009-08-28 05:46:19 +02:00
|
|
|
}
|
|
|
|
|
2009-02-21 09:39:26 +01:00
|
|
|
void bind_create_torrent()
|
|
|
|
{
|
2010-11-15 06:10:36 +01:00
|
|
|
void (file_storage::*add_file0)(std::string const&, size_type, int, std::time_t, std::string const&) = &file_storage::add_file;
|
2009-10-26 02:29:39 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2010-11-15 06:10:36 +01:00
|
|
|
void (file_storage::*add_file1)(std::wstring const&, size_type, int, std::time_t, std::string const&) = &file_storage::add_file;
|
2009-07-16 09:10:58 +02:00
|
|
|
#endif
|
2009-03-01 09:13:26 +01:00
|
|
|
|
|
|
|
void (file_storage::*set_name0)(std::string const&) = &file_storage::set_name;
|
2009-10-29 07:45:46 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2009-03-01 09:13:26 +01:00
|
|
|
void (file_storage::*set_name1)(std::wstring const&) = &file_storage::set_name;
|
2009-10-29 07:45:46 +01:00
|
|
|
#endif
|
2009-02-21 09:39:26 +01:00
|
|
|
|
2010-08-22 18:45:12 +02:00
|
|
|
#ifndef BOOST_NO_EXCEPTIONS
|
2009-10-26 02:29:39 +01:00
|
|
|
void (*set_piece_hashes0)(create_torrent&, std::string const&) = &set_piece_hashes;
|
2010-08-22 18:45:12 +02:00
|
|
|
#endif
|
2010-04-01 18:48:33 +02:00
|
|
|
void (*add_files0)(file_storage&, std::string const&, boost::uint32_t) = add_files;
|
2009-08-28 05:46:19 +02:00
|
|
|
|
2009-02-21 09:39:26 +01:00
|
|
|
class_<file_storage>("file_storage")
|
|
|
|
.def("is_valid", &file_storage::is_valid)
|
2010-11-15 06:10:36 +01:00
|
|
|
.def("add_file", add_file, (arg("entry"), arg("hash") = std::string(), arg("symlink") = std::string()))
|
|
|
|
.def("add_file", add_file0, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
|
2009-10-26 02:29:39 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2010-11-15 06:10:36 +01:00
|
|
|
.def("add_file", add_file1, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
|
2009-07-16 09:10:58 +02:00
|
|
|
#endif
|
2009-02-21 09:39:26 +01:00
|
|
|
.def("num_files", &file_storage::num_files)
|
|
|
|
.def("at", &file_storage::at, return_internal_reference<>())
|
|
|
|
.def("total_size", &file_storage::total_size)
|
|
|
|
.def("set_num_pieces", &file_storage::set_num_pieces)
|
|
|
|
.def("num_pieces", &file_storage::num_pieces)
|
|
|
|
.def("set_piece_length", &file_storage::set_piece_length)
|
|
|
|
.def("piece_length", &file_storage::piece_length)
|
|
|
|
.def("piece_size", &file_storage::piece_size)
|
2009-03-01 09:13:26 +01:00
|
|
|
.def("set_name", set_name0)
|
2009-10-29 07:45:46 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2009-03-01 09:13:26 +01:00
|
|
|
.def("set_name", set_name1)
|
2009-10-29 07:45:46 +01:00
|
|
|
#endif
|
2009-02-21 09:39:26 +01:00
|
|
|
.def("name", &file_storage::name, return_internal_reference<>())
|
|
|
|
;
|
|
|
|
|
|
|
|
class_<create_torrent>("create_torrent", no_init)
|
|
|
|
.def(init<file_storage&>())
|
|
|
|
.def(init<file_storage&, int>())
|
|
|
|
|
|
|
|
.def("generate", &create_torrent::generate)
|
|
|
|
|
|
|
|
.def("files", &create_torrent::files, return_internal_reference<>())
|
|
|
|
.def("set_comment", &create_torrent::set_comment)
|
|
|
|
.def("set_creator", &create_torrent::set_creator)
|
2009-08-28 05:46:19 +02:00
|
|
|
.def("set_hash", &set_hash)
|
2009-02-21 09:39:26 +01:00
|
|
|
.def("add_url_seed", &create_torrent::add_url_seed)
|
2010-05-22 10:21:40 +02:00
|
|
|
.def("add_node", &add_node)
|
2009-02-21 09:39:26 +01:00
|
|
|
.def("add_tracker", &create_torrent::add_tracker)
|
|
|
|
.def("set_priv", &create_torrent::set_priv)
|
|
|
|
.def("num_pieces", &create_torrent::num_pieces)
|
|
|
|
.def("piece_length", &create_torrent::piece_length)
|
|
|
|
.def("piece_size", &create_torrent::piece_size)
|
|
|
|
.def("priv", &create_torrent::priv)
|
|
|
|
;
|
2009-08-28 05:46:19 +02:00
|
|
|
|
2010-10-28 18:28:18 +02:00
|
|
|
def("add_files", add_files0, (arg("fs"), arg("path"), arg("flags") = 0));
|
2009-08-28 05:46:19 +02:00
|
|
|
def("set_piece_hashes", set_piece_hashes0);
|
2009-10-02 03:26:31 +02:00
|
|
|
def("set_piece_hashes", set_piece_hashes_callback);
|
2009-08-28 05:46:19 +02:00
|
|
|
|
2009-02-21 09:39:26 +01:00
|
|
|
}
|