【问题标题】:Is there a progress bar feature for pytube?pytube 有进度条功能吗?
【发布时间】:2019-09-16 20:24:39
【问题描述】:

我想在 youtube 下载功能中添加进度条。我需要哪些模块来表示这个栏?

我尝试导入 tqdm,并使用 for 循环创建了一个默认进度条,范围为 1000。 但是,我不知道如何将 tqdm 与 pytube 的 YouTube 类一起使用。

import pytube

video_url = "https://www.youtube.com/watch?v=DF5if13xSoo"
youtube = pytube.YouTube(video_url)
video = youtube.streams.first()
video.download('/Users/hargunoberoi/Desktop/Python/YoutubeTest')
print("Download Complete!")

代码正确下载了 youtube 视频,但我只是茫然地盯着命令行等待完成。 我想知道随着时间的推移下载了多少视频。

【问题讨论】:

  • 阅读文档。粗略的一瞥揭示了一些“进步”功能。您可能应该在pytube.Youtube(video_url) 中输入一些参数。
  • 感谢@101arrowz 的快速回复,我看到它要求用户定义的回调函数。那是什么意思?什么是样本输入?

标签: python python-3.x pytube


【解决方案1】:

请您Read The Fine Manual:

关于下载进度回调函数。

:param object stream:
    An instance of :class:`Stream <Stream>` being downloaded.
:param file_handle:
    The file handle where the media is being written to.
:type file_handle:
    :py:class:`io.BufferedWriter`
:param int bytes_remaining:
    How many bytes have been downloaded.

提供的示例调用是:

def download(url, itag):
    ...
    yt = YouTube(url, on_progress_callback=on_progress)

【讨论】:

    猜你喜欢
    • 2019-12-05
    • 2020-10-03
    • 2019-10-05
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    相关资源
    最近更新 更多