コード例 #1
0
ファイル: makemetafile.py プロジェクト: Konubinix/BitTornado
def make_meta_file(loc, url, params=None, flag=None,
                   progress=lambda x: None, progress_percent=True):
    """Make a single .torrent file for a given location"""
    if params is None:
        params = {}
    if flag is None:
        flag = threading.Event()

    tree = BTTree(loc, [])

    # Extract target from parameters
    if 'target' not in params or params['target'] == '':
        fname, ext = os.path.split(loc)
        if ext == '':
            target = fname + '.torrent'
        else:
            target = os.path.join(fname, ext + '.torrent')
        params['target'] = target

    info = tree.makeInfo(flag=flag, progress=progress,
                         progress_percent=progress_percent, **params)

    if flag is not None and flag.isSet():
        return

    metainfo = MetaInfo(announce=url, info=info, **params)
    metainfo.write(params['target'])
コード例 #2
0
ファイル: makemetafile.py プロジェクト: weedy/BitTornado
def make_meta_file(loc,
                   url,
                   params=None,
                   flag=None,
                   progress=lambda x: None,
                   progress_percent=True):
    """Make a single .torrent file for a given location"""
    if params is None:
        params = {}
    if flag is None:
        flag = threading.Event()

    tree = BTTree(loc, [])

    # Extract target from parameters
    if 'target' not in params or params['target'] == '':
        fname, ext = os.path.split(loc)
        if ext == '':
            target = fname + '.torrent'
        else:
            target = os.path.join(fname, ext + '.torrent')
        params['target'] = target

    info = tree.makeInfo(flag=flag,
                         progress=progress,
                         progress_percent=progress_percent,
                         **params)

    if flag is not None and flag.isSet():
        return

    metainfo = MetaInfo(announce=url, info=info, **params)
    metainfo.write(params['target'])
コード例 #3
0
ファイル: bt-t-make.py プロジェクト: hjwsm1989/BitTornado
 def _announcecopy(self, f):
     try:
         metainfo = MetaInfo.read(f)
         self.announce = metainfo['announce']
         self.announce_list = metainfo.get('announce-list')
     except:
         return
コード例 #4
0
ファイル: bt-t-make.py プロジェクト: Konubinix/BitTornado
 def _announcecopy(self, f):
     try:
         metainfo = MetaInfo.read(f)
         self.announce = metainfo["announce"]
         self.announce_list = metainfo.get("announce-list")
     except:
         return
コード例 #5
0
ファイル: btrename.py プロジェクト: weedy/BitTornado
def rename(fname, newname, verbose=False):
    metainfo = MetaInfo.read(fname)

    if verbose:
        print "%s: %s -> %s" % (fname, metainfo['info']['name'], newname)

    metainfo['info']['name'] = newname

    metainfo.write(fname)
コード例 #6
0
ファイル: bt-t-make.py プロジェクト: Konubinix/BitTornado
 def _announcecopy(self, f, external=False):
     try:
         metainfo = MetaInfo.read(f)
         self.annCtl.SetValue(metainfo["announce"])
         if "announce-list" in metainfo:
             self.annListCtl.SetValue("\n".join(", ".join(tier) for tier in metainfo["announce-list"]) + "\n" * 3)
         else:
             self.annListCtl.SetValue("")
         if external:
             self.choices.SetSelection(0)
             self.choices1.SetSelection(0)
     except:
         return
コード例 #7
0
ファイル: btmaketorrentgui.py プロジェクト: weedy/BitTornado
 def announcecopy(self, x):
     dl = wx.wxFileDialog(self.frame, 'Choose .torrent file to use', '', '',
                          '*.torrent', wx.wxOPEN)
     if dl.ShowModal() == wx.wxID_OK:
         try:
             metainfo = MetaInfo.read(dl.GetPath())
             self.annCtl.SetValue(metainfo['announce'])
             if 'announce-list' in metainfo:
                 self.annListCtl.SetValue(
                     '\n'.join(', '.join(tier) for tier in
                               metainfo['announce-list']) + '\n' * 3)
             else:
                 self.annListCtl.SetValue('')
         except:
             return
コード例 #8
0
ファイル: bt-t-make.py プロジェクト: hjwsm1989/BitTornado
 def _announcecopy(self, f, external=False):
     try:
         metainfo = MetaInfo.read(f)
         self.annCtl.SetValue(metainfo['announce'])
         if 'announce-list' in metainfo:
             self.annListCtl.SetValue('\n'.join(
                 ', '.join(tier)
                 for tier in metainfo['announce-list']) + '\n' * 3)
         else:
             self.annListCtl.SetValue('')
         if external:
             self.choices.SetSelection(0)
             self.choices1.SetSelection(0)
     except:
         return
コード例 #9
0
ファイル: btsethttpseeds.py プロジェクト: weedy/BitTornado
def main(argv):
    program, ext = os.path.splitext(os.path.basename(argv[0]))
    usage = """Usage: %s <http-seeds> file1.torrent [file2.torrent...]

  Where:
    http-seeds = list of seed URLs, in the format:
        url[|url...] or 0
            if the list is a zero, any http seeds will be stripped.
""" % program

    try:
        opts, args = getopt.getopt(argv[1:], "hv", ("help", "verbose"))
    except getopt.error as msg:
        print msg
        return 1

    if len(args) < 2:
        print usage
        return 2

    http_seeds = None
    if args[0] != '0':
        http_seeds = args[0].split('|')

    verbose = False

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            print usage
            return 0
        elif opt in ('-v', '--verbose'):
            verbose = True

    for fname in args[1:]:
        metainfo = MetaInfo.read(fname)

        if 'httpseeds' in metainfo:
            if verbose:
                print 'old http-seed list for {}: {}'.format(
                    fname, '|'.join(metainfo['httpseeds']))
            if http_seeds is None:
                del metainfo['httpseeds']

        if http_seeds is not None:
            metainfo['httpseeds'] = http_seeds

        metainfo.write(fname)
コード例 #10
0
def main(argv):
    program, ext = os.path.splitext(os.path.basename(argv[0]))
    usage = """Usage: %s <http-seeds> file1.torrent [file2.torrent...]

  Where:
    http-seeds = list of seed URLs, in the format:
        url[|url...] or 0
            if the list is a zero, any http seeds will be stripped.
""" % program

    try:
        opts, args = getopt.getopt(argv[1:], "hv", ("help", "verbose"))
    except getopt.error as msg:
        print msg
        return 1

    if len(args) < 2:
        print usage
        return 2

    http_seeds = None
    if args[0] != '0':
        http_seeds = args[0].split('|')

    verbose = False

    for opt, arg in opts:
        if opt in ('-h', '--help'):
            print usage
            return 0
        elif opt in ('-v', '--verbose'):
            verbose = True

    for fname in args[1:]:
        metainfo = MetaInfo.read(fname)

        if 'httpseeds' in metainfo:
            if verbose:
                print 'old http-seed list for {}: {}'.format(
                    fname, '|'.join(metainfo['httpseeds']))
            if http_seeds is None:
                del metainfo['httpseeds']

        if http_seeds is not None:
            metainfo['httpseeds'] = http_seeds

        metainfo.write(fname)
コード例 #11
0
def main(argv):
    """Copy announce information from source to all specified torrents"""
    program, _ext = os.path.splitext(os.path.basename(argv[0]))
    usage = "Usage: %s <source.torrent> <file1.torrent> " \
            "[file2.torrent...]" % program
    try:
        opts, args = getopt.getopt(argv[1:], "hv",
                                   ("help", "verbose"))
    except getopt.error as msg:
        print msg
        return 1

    if len(args) < 2:
        print "%s\n%s\n" % (usage, main.__doc__)
        return 2

    source_metainfo = MetaInfo.read(args[0])

    verbose = False

    for opt, _arg in opts:
        if opt in ('-h', '--help'):
            print "%s\n%s\n" % (usage, main.__doc__)
            return 0
        elif opt in ('-v', '--verbose'):
            verbose = True

    announce = source_metainfo['announce']
    announce_list = source_metainfo.get('announce-list')

    if verbose:
        print 'new announce: ' + announce
        if announce_list:
            print 'new announce-list: ' + \
                '|'.join(','.join(tier) for tier in announce_list)

    for fname in args[1:]:
        reannounce(fname, announce, announce_list, verbose)

    return 0
コード例 #12
0
def main(argv):
    """Copy announce information from source to all specified torrents"""
    program, _ext = os.path.splitext(os.path.basename(argv[0]))
    usage = "Usage: %s <source.torrent> <file1.torrent> " \
            "[file2.torrent...]" % program
    try:
        opts, args = getopt.getopt(argv[1:], "hv", ("help", "verbose"))
    except getopt.error as msg:
        print msg
        return 1

    if len(args) < 2:
        print "%s\n%s\n" % (usage, main.__doc__)
        return 2

    source_metainfo = MetaInfo.read(args[0])

    verbose = False

    for opt, _arg in opts:
        if opt in ('-h', '--help'):
            print "%s\n%s\n" % (usage, main.__doc__)
            return 0
        elif opt in ('-v', '--verbose'):
            verbose = True

    announce = source_metainfo['announce']
    announce_list = source_metainfo.get('announce-list')

    if verbose:
        print 'new announce: ' + announce
        if announce_list:
            print 'new announce-list: ' + \
                '|'.join(','.join(tier) for tier in announce_list)

    for fname in args[1:]:
        reannounce(fname, announce, announce_list, verbose)

    return 0
コード例 #13
0
from BitTornado.Info import MetaInfo
from BitTornado.bencode import bencode

NAME, EXT = os.path.splitext(os.path.basename(sys.argv[0]))
VERSION = '20130326'

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

if len(sys.argv) == 1:
    print '%s file1.torrent file2.torrent file3.torrent ...' % sys.argv[0]
    print
    sys.exit(2)     # common exit code for syntax error

for metainfo_name in sys.argv[1:]:
    metainfo = MetaInfo.read(metainfo_name)
    info = metainfo['info']
    info_hash = hashlib.sha1(bencode(info))

    print 'metainfo file.: %s' % os.path.basename(metainfo_name)
    print 'info hash.....: %s' % info_hash.hexdigest()
    piece_length = info['piece length']
    if 'length' in info:
        # 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.........: '