问题
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