Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
#!/usr/bin/env python
2
 
3
# Written by Henry 'Pi' James and Loring Holden
4
# modified for multitracker display by John Hoffman
5
# see LICENSE.txt for license information
6
 
7
from sys import *
8
from os.path import *
9
from sha import *
10
from BitTornado.bencode import *
11
 
12
NAME, EXT = splitext(basename(argv[0]))
13
VERSION = '20030621'
14
 
15
print '%s %s - decode BitTorrent metainfo files' % (NAME, VERSION)
16
print
17
 
18
if len(argv) == 1:
19
    print '%s file1.torrent file2.torrent file3.torrent ...' % argv[0]
20
    print
21
    exit(2) # common exit code for syntax error
22
 
23
for metainfo_name in argv[1:]:
24
    metainfo_file = open(metainfo_name, 'rb')
25
    metainfo = bdecode(metainfo_file.read())
26
#    print metainfo
27
    info = metainfo['info']
28
    info_hash = sha(bencode(info))
29
 
30
    print 'metainfo file.: %s' % basename(metainfo_name)
31
    print 'info hash.....: %s' % info_hash.hexdigest()
32
    piece_length = info['piece length']
33
    if info.has_key('length'):
34
        # let's assume we just have a file
35
        print 'file name.....: %s' % info['name']
36
        file_length = info['length']
37
        name ='file size.....:'
38
    else:
39
        # let's assume we have a directory structure
40
        print 'directory name: %s' % info['name']
41
        print 'files.........: '
42
        file_length = 0;
43
        for file in info['files']:
44
            path = ''
45
            for item in file['path']:
46
                if (path != ''):
47
                   path = path + "/"
48
                path = path + item
49
            print '   %s (%d)' % (path, file['length'])
50
            file_length += file['length']
51
            name ='archive size..:'
52
    piece_number, last_piece_length = divmod(file_length, piece_length)
53
    print '%s %i (%i * %i + %i)' \
54
          % (name,file_length, piece_number, piece_length, last_piece_length)
55
    print 'announce url..: %s' % metainfo['announce']
56
    if metainfo.has_key('announce-list'):
57
        list = []
58
        for tier in metainfo['announce-list']:
59
            for tracker in tier:
60
                list+=[tracker,',']
61
            del list[-1]
62
            list+=['|']
63
        del list[-1]
64
        liststring = ''
65
        for i in list:
66
            liststring+=i
67
        print 'announce-list.: %s' % liststring
68
    if metainfo.has_key('httpseeds'):
69
        list = []
70
        for seed in metainfo['httpseeds']:
71
            list += [seed,'|']
72
        del list[-1]
73
        liststring = ''
74
        for i in list:
75
            liststring+=i
76
        print 'http seeds....: %s' % liststring
77
    if metainfo.has_key('comment'):
78
        print 'comment.......: %s' % metainfo['comment']