3

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.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
hargun3045
  • 306
  • 3
  • 9
  • 1
    Read the docs. A cursory glance reveals a few 'progress' functions. There might be some parameters you should put in `pytube.Youtube(video_url)`. – 101arrowz Apr 27 '19 at 16:32
  • 1
    Thanks for the quick response @101arrowz I see that it asks for a user-defined callback function. What does that mean? What could be a sample input? – hargun3045 Apr 27 '19 at 16:48

1 Answers1

3

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)
J_H
  • 17,926
  • 4
  • 24
  • 44