Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add tqdm to show progress bar when downloading you tube video with pytube?

I am learning pytube to download Youtube video and tried tqdm on top of it to show progress bar but it shows various error and also I could not understand what is happening when I download video with pytube and showing progress bar which is the reason for me to not able to add tqdm in it.

The code I have written with pytube runs well, this is the code:

from pytube import YouTube


url = str(input("Enter the video link: "))
yt = YouTube(url)
videos = yt.streams.filter(file_extension='mp4').all()

filename = yt.title


s = 1
for v in videos:
    print(str(s)+". "+str(v))
    s += 1

n = int(input("Enter the number of the video: "))
vid = videos[n-1]

vid.download("C:/Users/user/Downloads/")

print(yt.title,"\nHas been successfully downloaded")

I need tqdm to be added to the code to show a progress bar.

like image 983
Jackson Jegatheesan Avatar asked May 06 '19 07:05

Jackson Jegatheesan


1 Answers

I don't know about tqdm, but there is a progress bar feature for pytube.

I use it like this:

from pytube.cli import on_progress
from pytube import YouTube as YT
...
yt = YT(video_url, on_progress_callback=on_progress)
yt.streams\
  .filter(file_extension='mp4')\
  .get_lowest_resolution()\
  .download(video_path)

Looks like this:

PSY - GANGNAM STYLE(강남스타일) MV.mp4
↳ |███████████████████████████████████████| 100.0%

Hope it helps!

like image 113
rusito23 Avatar answered Oct 04 '22 04:10

rusito23