【问题标题】:Error while implementing progress_bar in pytube3在 pytube3 中实现 progress_bar 时出错
【发布时间】:2020-06-15 09:36:48
【问题描述】:

我正在使用 pytube3 实现一个 youtube 视频下载器。在以下progress_bar() 函数中,我收到positional argument 缺失错误。

我的 progress_bar() 函数:

def progress_bar(stream, chunk, file_handle, bytes_remaining):
    file_downloaded = file_size - bytes_remaining
    percentage = (file_downloaded / file_size) * 100
    print(f'{percentage :00.0f}% done...')

我的 YouTube() 对象:

yt_object = YouTube(url, on_progress_callback=progress_bar)

显示或打印进度时出现以下错误

progress_bar() missing 1 required positional argument: 'bytes_remaining'

如果我确实删除了 YouTube 对象(即 yt_object)中的 progress_bar 引用,则文件正在成功下载,但我在实现 progress_bar() 时遇到错误。

【问题讨论】:

    标签: python youtube pytube


    【解决方案1】:

    遇到同样的问题。这样解决了:

    from pytube import YouTube
    from pytube.cli import on_progress
    
    def download_video(url):
        yt = YouTube(url, on_progress_callback=on_progress)
        stream = yt.streams.first()
        print("start to download url: " + url)
        print(stream.title)
        stream.download(DOWNLOAD_DIR)
    

    【讨论】:

      猜你喜欢
      • 2012-12-28
      • 2021-05-11
      • 2018-06-04
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多