Is there a progress bar feature for pytube?

让人想犯罪 __ 提交于 2021-01-29 04:00:49

问题


I want to add a progress bar to the youtube download feature. what modules do I need to represent this bar?

I tried importing tqdm and I created a default progress bar using a for loop over a range of 1000. However, I don't know how I'll use tqdm with the YouTube class from pytube.

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!")

The code correctly downloads the youtube videos, but I just stare blankly at the command line waiting for the completion. I want to know how much of the video is downloaded over time.


回答1:


We ask that you please Read The Fine Manual:

On download progress callback function.

: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.

The example call provided is:

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


来源:https://stackoverflow.com/questions/55882563/is-there-a-progress-bar-feature-for-pytube

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!