def torrent_info(request, filename): metaname = settings.MEDIA_ROOT + filename metafile = open(metaname, "rb") metainfo = bdecode(metafile.read()) metafile.close() info = metainfo['info'] info_hash = sha(bencode(info)).hexdigest() title = metainfo.get('title', '') #filename piece_length = info['piece length'] if info.has_key('length'): # single file mode path_name = '' files = [ { 'fname':info['name'], 'length':info['length'], 'content_type':info.get('content_type','') }, ] file_length = info['length'] else: # multiple files mode path_name = info['name'] files = [] file_length = 0 for file in info['files']: path = "/".join( file["path"] ) files.append( { 'fname':path, 'length':file['length'], 'content_type':file.get('content_type',''), } ) file_length += file['length'] piece_number, last_piece_length = divmod(file_length, piece_length) announce = metainfo.get('announce','') announce_list = metainfo.get('announce-list','') nodes = map(lambda n:{'ip':n[0], 'port':n[1]}, metainfo['nodes']) comment = metainfo.get('comment','') url_list = metainfo.get('url-list', '') create_date = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime(metainfo.get('creation date', 0))) return render_to_response('bitinfo/torrent_info.html', locals(), RequestContext(request) )
} maxlength = max( [len(v[:v.find(':')]) for v in labels.values()] ) # run through l10n-ed labels and make them all the same length for k,v in labels.items(): if ':' in v: index = v.index(':') newlabel = v.replace(':', '.'*(maxlength-index) + ':') labels[k] = newlabel for metainfo_name in argv[1:]: metainfo_file = open(metainfo_name, 'rb') metainfo = bdecode(metainfo_file.read()) metainfo_file.close() info = metainfo['info'] info_hash = sha(bencode(info)) if metainfo.has_key('title'): print labels['title'] % metainfo['title'] print labels['metafile'] % basename(metainfo_name) print labels['infohash'] % info_hash.hexdigest() piece_length = info['piece length'] if info.has_key('length'): # let's assume we just have a file print labels['filename'] % info['name'] file_length = info['length'] name = labels['filesize'] if info.has_key('content_type'): print labels['content_type'] % info['content_type'] else: # let's assume we have a directory structure
} maxlength = max([len(v[:v.find(':')]) for v in labels.values()]) # run through l10n-ed labels and make them all the same length for k, v in labels.items(): if ':' in v: index = v.index(':') newlabel = v.replace(':', '.' * (maxlength - index) + ':') labels[k] = newlabel for metainfo_name in argv[1:]: metainfo_file = open(metainfo_name, 'rb') metainfo = bdecode(metainfo_file.read()) metainfo_file.close() info = metainfo['info'] info_hash = sha(bencode(info)) if metainfo.has_key('title'): print labels['title'] % metainfo['title'] print labels['metafile'] % basename(metainfo_name) print labels['infohash'] % info_hash.hexdigest() piece_length = info['piece length'] if info.has_key('length'): # let's assume we just have a file print labels['filename'] % info['name'] file_length = info['length'] name = labels['filesize'] if info.has_key('content_type'): print labels['content_type'] % info['content_type'] else: # let's assume we have a directory structure