~ubuntu-branches/ubuntu/oneiric/bittornado/oneiric

« back to all changes in this revision

Viewing changes to btshowmetainfo.py

  • Committer: Bazaar Package Importer
  • Author(s): Cameron Dale
  • Date: 2010-03-21 14:36:30 UTC
  • Revision ID: james.westby@ubuntu.com-20100321143630-d1zk1zdasaf8125s
Tags: 0.3.18-10
* New patch from upstream's CVS to allow torrents that only have an
  announce list: 30_announce_list_only_torrents.dpatch (Closes: #551766)
* Fix a lot of lintian warnings
  - Update standards version to 3.8.4 (no changes)
* Fix for when compact_reqd is turned off:
  31_fix_for_compact_reqd_off.dpatch (Closes: #574860)
* Switch to the new "3.0 (quilt)" source format

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    exit(2) # common exit code for syntax error
22
22
 
23
23
for metainfo_name in argv[1:]:
 
24
    print 'metainfo file.: %s' % basename(metainfo_name)
 
25
 
24
26
    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']
 
27
    metainfo = metainfo_file.read()
 
28
    metainfo_file.close()
 
29
    metainfo = bdecode(metainfo)
 
30
    try:    
 
31
        info = metainfo['info']
 
32
        info_hash = sha(bencode(info))
 
33
 
 
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.....:'
 
41
        else:
 
42
            # let's assume we have a directory structure
 
43
            print 'directory name: %s' % info['name']
 
44
            print 'files.........: '
 
45
            file_length = 0;
 
46
            for file in info['files']:
 
47
                path = ''
 
48
                for item in file['path']:
 
49
                    if (path != ''):
 
50
                       path = path + "/"
 
51
                    path = path + item
 
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']
 
60
        else:
 
61
            print '***WARNING*** - no announce key'
 
62
        if metainfo.has_key('announce-list'):
 
63
            list = []
 
64
            for tier in metainfo['announce-list']:
 
65
                for tracker in tier:
 
66
                    list+=[tracker,',']
 
67
                del list[-1]
 
68
                list+=['|']
 
69
            del list[-1]
 
70
            liststring = ''
 
71
            for i in list:
 
72
                liststring+=i
 
73
            print 'announce-list.: %s' % liststring
 
74
        if metainfo.has_key('httpseeds'):
 
75
            list = []
 
76
            for seed in metainfo['httpseeds']:
 
77
                list += [seed,'|']
 
78
            del list[-1]
 
79
            liststring = ''
 
80
            for i in list:
 
81
                liststring+=i
 
82
            print 'http seeds....: %s' % liststring
 
83
        if metainfo.has_key('comment'):
 
84
            print 'comment.......: %s' % metainfo['comment']
 
85
 
 
86
    except:
 
87
        print '***ERROR*** - metainfo out of spec'