-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshowmetainfo.py
executable file
·69 lines (61 loc) · 2.39 KB
/
showmetainfo.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/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 Henry 'Pi' James and Loring Holden
# Modified for Anomos by John Schanck
from sys import *
from os.path import *
from sha import *
from Anomos.bencode import *
NAME, EXT = splitext(basename(argv[0]))
VERSION = '20090730'
print '%s %s - decode Anomos metainfo files' % (NAME, VERSION)
print
if len(argv) == 1:
print '%s file1.atorrent file2.atorrent file3.atorrent ...' % argv[0]
print
exit(2) # common exit code for syntax error
for metainfo_name in argv[1:]:
metainfo_file = open(metainfo_name, 'rb')
metainfo = bdecode(metainfo_file.read())
metainfo_file.close()
announce = metainfo['announce']
info = metainfo['info']
info_hash = sha(bencode(info))
print 'metainfo file.: %s' % basename(metainfo_name)
print 'info hash.....: %s' % info_hash.hexdigest()
piece_length = info['piece length']
if info.has_key('length'):
# let's assume we just have a file
print 'file name.....: %s' % info['name']
file_length = info['length']
name ='file size.....:'
else:
# let's assume we have a directory structure
print 'directory name: %s' % info['name']
print 'files.........: '
file_length = 0;
for file in info['files']:
path = ''
for item in file['path']:
if (path != ''):
path = path + "/"
path = path + item
print ' %s (%d)' % (path, file['length'])
file_length += file['length']
name = 'archive size..:'
piece_number, last_piece_length = divmod(file_length, piece_length)
print '%s %i (%i * %i + %i)' \
% (name,file_length, piece_number, piece_length, last_piece_length)
print 'announce url..: %s' % announce
print