使用pytube下载管视频时如何添加tqdm以显示进度条?

Jac*_*san 7 python youtube python-3.6 tqdm pytube

我正在学习pytube下载 Youtube 视频并尝试tqdm在它上面显示进度条,但它显示了各种错误,而且我无法理解当我下载视频pytube并显示进度条时发生了什么,这是我无法显示的原因加tqdm进去。

我写的代码pytube运行良好,这是代码:

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

Run Code Online (Sandbox Code Playgroud)

我需要tqdm添加到代码中才能显示进度条。

rus*_*o23 9

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

\n\n

我这样使用它:

\n\n
from pytube.cli import on_progress\nfrom pytube import YouTube as YT\n...\nyt = YT(video_url, on_progress_callback=on_progress)\nyt.streams\\\n  .filter(file_extension=\'mp4\')\\\n  .get_lowest_resolution()\\\n  .download(video_path)\n
Run Code Online (Sandbox Code Playgroud)\n\n

看起来像这样:

\n\n
PSY - GANGNAM STYLE(\xea\xb0\x95\xeb\x82\xa8\xec\x8a\xa4\xed\x83\x80\xec\x9d\xbc) MV.mp4\n\xe2\x86\xb3 |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 100.0%\n
Run Code Online (Sandbox Code Playgroud)\n\n

希望能帮助到你!

\n