本文介绍了使用pytube下载管视频时如何添加tqdm以显示进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 pytube 下载 Youtube 视频并尝试 tqdm 在它上面显示进度条,但它显示了各种错误,我也不明白发生了什么当我使用 pytube 下载视频并显示进度条时,这是我无法在其中添加 tqdm 的原因.

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.

我用pytube写的代码运行良好,代码如下:

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

我需要将 tqdm 添加到代码中以显示进度条.

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

推荐答案

我不知道tqdm,但是有一个进度条功能 pytube.

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

我是这样使用的:

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)

看起来像这样:

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

希望有帮助!

这篇关于使用pytube下载管视频时如何添加tqdm以显示进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 10:24