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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With