forked from premiere/premiere-libtorrent
added make_torrent.py example and polished the python binding for creating torrents
This commit is contained in:
parent
381f42bcf2
commit
eaedc22831
|
@ -0,0 +1,27 @@
|
|||
#!/bin/python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import libtorrent
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print 'usage make_torrent.py file tracker-url'
|
||||
sys.exit(1)
|
||||
|
||||
input = os.path.abspath(sys.argv[1])
|
||||
|
||||
fs = libtorrent.file_storage()
|
||||
libtorrent.add_files(fs, input)
|
||||
if fs.num_files() == 0:
|
||||
print 'no files added'
|
||||
sys.exit(1)
|
||||
|
||||
t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024)
|
||||
|
||||
t.add_tracker(sys.argv[2])
|
||||
t.set_creator('libtorrent %s' % libtorrent.version)
|
||||
|
||||
libtorrent.set_piece_hashes(t, os.path.split(input)[0], lambda x: sys.stderr.write('.'))
|
||||
sys.stderr.write('\n')
|
||||
|
||||
print libtorrent.bencode(t.generate())
|
|
@ -103,7 +103,8 @@ void bind_create_torrent()
|
|||
|
||||
class_<create_torrent>("create_torrent", no_init)
|
||||
.def(init<file_storage&>())
|
||||
.def(init<file_storage&, int>())
|
||||
.def(init<file_storage&, int, int, int>((arg("storage"), arg("piece_size") = 0
|
||||
, arg("pad_file_limit") = -1, arg("flags") = int(libtorrent::create_torrent::optimize))))
|
||||
|
||||
.def("generate", &create_torrent::generate)
|
||||
|
||||
|
@ -113,7 +114,7 @@ void bind_create_torrent()
|
|||
.def("set_hash", &set_hash)
|
||||
.def("add_url_seed", &create_torrent::add_url_seed)
|
||||
.def("add_node", &add_node)
|
||||
.def("add_tracker", &create_torrent::add_tracker)
|
||||
.def("add_tracker", &create_torrent::add_tracker, (arg("announce_url"), arg("tier") = 0))
|
||||
.def("set_priv", &create_torrent::set_priv)
|
||||
.def("num_pieces", &create_torrent::num_pieces)
|
||||
.def("piece_length", &create_torrent::piece_length)
|
||||
|
@ -121,6 +122,13 @@ void bind_create_torrent()
|
|||
.def("priv", &create_torrent::priv)
|
||||
;
|
||||
|
||||
enum_<create_torrent::flags_t>("create_torrent_flags_t")
|
||||
.value("optimize", create_torrent::optimize)
|
||||
.value("merkle", create_torrent::merkle)
|
||||
.value("modification_time", create_torrent::modification_time)
|
||||
.value("symlinks", create_torrent::symlinks)
|
||||
;
|
||||
|
||||
def("add_files", add_files0, (arg("fs"), arg("path"), arg("flags") = 0));
|
||||
def("set_piece_hashes", set_piece_hashes0);
|
||||
def("set_piece_hashes", set_piece_hashes_callback);
|
||||
|
|
|
@ -65,7 +65,8 @@ namespace libtorrent
|
|||
|
||||
struct TORRENT_EXPORT create_torrent
|
||||
{
|
||||
enum {
|
||||
enum flags_t
|
||||
{
|
||||
optimize = 1
|
||||
, merkle = 2
|
||||
, modification_time = 4
|
||||
|
|
Loading…
Reference in New Issue