forked from Miserlou/Anomos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeatorrent.py
executable file
·55 lines (47 loc) · 2.13 KB
/
makeatorrent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Written by Bram Cohen
import sys
from Anomos.makemetafile import make_meta_files
from Anomos.parseargs import parseargs, printHelp
from Anomos import BTFailure
defaults = [
('piece_size_pow2', 18,
"which power of 2 to set the piece size to"),
('comment', '',
"optional human-readable comment to put in .torrent"),
('target', '',
"optional target file for the torrent"),
('filesystem_encoding', '',
"character encoding used on the local filesystem. If left empty, autodetected. Autodetection doesn't work under python versions older than 2.3.")
]
def dc(v):
print v
def prog(amount):
print '%.1f%% complete\r' % (amount * 100),
if __name__ == '__main__':
if len(sys.argv) <= 1:
printHelp('btmaketorrent', defaults)
else:
try:
config, args = parseargs(sys.argv[1:], defaults, 2, None)
print config
print args
if len(sys.argv) == 3:
make_meta_files(args[0], args[1:], piece_len_pow2=config['piece_size_pow2'], progressfunc=prog, filefunc=dc, comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'])
else:
make_meta_files(args[0], args[2:], piece_len_pow2=config['piece_size_pow2'], progressfunc=prog, filefunc=dc, comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'])
except BTFailure, e:
print str(e)
sys.exit(1)