Example #1
0
def get_scrape_by_metadata(metadata):
    if metadata is None:
        return '?','?'

    info = metadata.get('info',None)
    if not info:
        return '?','?'

    infohash = sha(bencode(info)).digest()
    announce_url = metadata.get('announce',None)
    announce_list = metadata.get('announce-list',None)
    if not announce_url and not announce_list:
        return '?','?'

    if not announce_url:
        announce_url = announce_list[0][0]

    return get_scrape_by_announce_url(announce_url,infohash)
# see LICENSE.txt for license information

from sys import *
from os.path import *
from sha import *
from BitTornado.bencode import *

NAME, EXT = splitext(basename(argv[0]))
VERSION = '20021119'

print '%s %s - change the suggested filename in a .torrent file' % (NAME, VERSION)
print

if len(argv) != 3:
  print '%s file.torrent new.filename.ext' % argv[0]
  print
  exit(2) # common exit code for syntax error

metainfo_file = open(argv[1], 'rb')
metainfo = bdecode(metainfo_file.read())
metainfo_file.close()
print 'old filename: %s' % metainfo['info']['name']
metainfo['info']['name'] = argv[2]
print 'new filename: %s' % metainfo['info']['name']
metainfo_file = open(argv[1], 'wb')
metainfo_file.write(bencode(metainfo))
metainfo_file.close
print
print 'done.'
print
VERSION = '20030621'

print '%s %s - decode BitTorrent metainfo files' % (NAME, VERSION)
print

if len(argv) == 1:
    print '%s file1.torrent file2.torrent file3.torrent ...' % 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())
#    print metainfo
    info = metainfo['info']
    info_hash = sha1(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']:
Example #4
0
VERSION = '20030621'

print '%s %s - decode BitTorrent metainfo files' % (NAME, VERSION)
print

if len(argv) == 1:
    print '%s file1.torrent file2.torrent file3.torrent ...' % 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())
    #    print metainfo
    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']:
Example #5
0
from sys import *
from os.path import *
from sha import *
from BitTornado.bencode import *

NAME, EXT = splitext(basename(argv[0]))
VERSION = '20021119'

print '%s %s - change the suggested filename in a .torrent file' % (NAME,
                                                                    VERSION)
print

if len(argv) != 3:
    print '%s file.torrent new.filename.ext' % argv[0]
    print
    exit(2)  # common exit code for syntax error

metainfo_file = open(argv[1], 'rb')
metainfo = bdecode(metainfo_file.read())
metainfo_file.close()
print 'old filename: %s' % metainfo['info']['name']
metainfo['info']['name'] = argv[2]
print 'new filename: %s' % metainfo['info']['name']
metainfo_file = open(argv[1], 'wb')
metainfo_file.write(bencode(metainfo))
metainfo_file.close
print
print 'done.'
print
Example #6
0
        # write out to a local file
        of = open( filestr, "wb" )
        of.write( f.read() )
        of.close()
        metainfo_name = filestr

    # owners have to match
    if not isFileOwnerCurrentUser( metainfo_name ):
        print 'You do not own torrent \'%s\'' % metainfo_name
        continue

    metainfo_file = open(metainfo_name, 'rb')
    metainfo = bdecode(metainfo_file.read())
    metainfo_file.close()
    info = metainfo['info']
    info_hash = sha( bencode( info    ) ).hexdigest()

    # allowed tracker?
    if not isTrackerAllowed( metainfo['announce'] ):
        print 'Tracker for \'%s\' is not allowed.' % info['name']
        continue

    ## make sure we havent downloaded this already
    if checkDownloadStatus( info ) and not forceDownload:
        print "A torrent with the hash %s has already been downloaded." % info_hash
    else:    
        if info.has_key('length'):
            fileSize = info['length']
        else:
            fileSize = 0;
            for file in info['files']: