added make_torrent.py example and polished the python binding for creating torrents

This commit is contained in:
Arvid Norberg
2011-04-10 08:41:07 +00:00
parent 381f42bcf2
commit eaedc22831
3 changed files with 39 additions and 3 deletions

View File

@@ -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())