コード例 #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'])