downloader.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:EMFT 作者: 132nd-etcher 项目源码 文件源码
def download(
    url,
    local_file,
    file_size: int = None,
    hexdigest: str = None,
    title: str = '',
):
    LOGGER.info('downloading {} -> {}'.format(url, local_file))

    if not title:
        title = f'Downloading {url.split("/")[-1]}'

    Progress.start(
        title=title,
        label=f'Downloading to: {local_file}',
    )

    def _progress_hook(data):
        label = 'Time left: {} ({}/{})'.format(
            data['time'],
            humanize.naturalsize(data['downloaded']),
            humanize.naturalsize(data['total'])
        )
        Progress.set_label(label)
        Progress.set_value(data['downloaded'] / data['total'] * 100)

    # def hook(data):
    #     # I.progress_set_value(int(float(data['percent_complete'])))
    #     Progress().set_value(int(float(data['percent_complete'])))

    time.sleep(1)
    dl = Downloader(
        url=url,
        filename=local_file,
        progress_hooks=[_progress_hook],
        content_length=file_size,
        hexdigest=hexdigest
    )
    return dl.download()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号