3
# Written by Henry 'Pi' James and Loring Holden
4
# modified for multitracker display by John Hoffman
5
# see LICENSE.txt for license information
10
from BitTornado.bencode import *
12
NAME, EXT = splitext(basename(argv[0]))
15
print '%s %s - decode BitTorrent metainfo files' % (NAME, VERSION)
19
print '%s file1.torrent file2.torrent file3.torrent ...' % argv[0]
21
exit(2) # common exit code for syntax error
23
for metainfo_name in argv[1:]:
24
print 'metainfo file.: %s' % basename(metainfo_name)
26
metainfo_file = open(metainfo_name, 'rb')
27
metainfo = metainfo_file.read()
29
metainfo = bdecode(metainfo)
31
info = metainfo['info']
32
info_hash = sha(bencode(info))
34
print 'info hash.....: %s' % info_hash.hexdigest()
35
piece_length = info['piece length']
36
if info.has_key('length'):
37
# let's assume we just have a file
38
print 'file name.....: %s' % info['name']
39
file_length = info['length']
40
name ='file size.....:'
42
# let's assume we have a directory structure
43
print 'directory name: %s' % info['name']
44
print 'files.........: '
46
for file in info['files']:
48
for item in file['path']:
52
print ' %s (%d)' % (path, file['length'])
53
file_length += file['length']
54
name ='archive size..:'
55
piece_number, last_piece_length = divmod(file_length, piece_length)
56
print '%s %i (%i * %i + %i)' \
57
% (name,file_length, piece_number, piece_length, last_piece_length)
58
if metainfo.has_key('announce'):
59
print 'announce url..: %s' % metainfo['announce']
61
print '***WARNING*** - no announce key'
62
if metainfo.has_key('announce-list'):
64
for tier in metainfo['announce-list']:
73
print 'announce-list.: %s' % liststring
74
if metainfo.has_key('httpseeds'):
76
for seed in metainfo['httpseeds']:
82
print 'http seeds....: %s' % liststring
83
if metainfo.has_key('comment'):
84
print 'comment.......: %s' % metainfo['comment']
87
print '***ERROR*** - metainfo out of spec'