问题描述
pytube是一个轻量级的,无依赖项的Python库,用于从Web下载视频。
我想在代码中使用progressBar来显示YouTube视频下载的当前状态,下面是我的代码。
from pytube import YouTube
from tqdm import tqdm # progressbar library
import time
# for converting data into kb
chunk_size = 1024
# https://www.youtube.com/watch?v=d3D7Y_ycSms
def start_download(link):
global count
count = 0
flag = True
while flag:
try:
print("entered")
yt = YouTube(link)
# video_type = yt.streams.filter(progressive=True,file_extension='mp4').first()
print("linked url")
if yt is not None:
flag = False
else:
continue
except:
count += 1
print("ERROR. Check your:\n -connection\n -url is a YouTube url\n\nTry again.")
# call function for restart download
if count >3:
print("Network Connection: Poor. Please check your internet connection")
flag = False
else:
start_download(link)
time.sleep(0.5)
print("Network Connection: OK")
time.sleep(1)
#Showing details
print("Title: ",yt.title)
time.sleep(0.02)
print("Number of views: ",yt.views)
time.sleep(0.02)
print("Length of video: ",yt.length)
time.sleep(0.02)
print("rating of video: ",yt.rating)
time.sleep(0.02)
# file size
# print('FileSize : ' + str(round(video_type.filesize/(1024*1024))) + 'MB')
time.sleep(1)
# ProgressBar
for i in tqdm(range(100),desc="Downloading...",ascii=True,ncols=100):
time.sleep(0.03)
# Download video
print("Downloading...")
video_type.download()
print("Done")
# youtube url
link = input("Enter the link of YouTube video you want to download: ")
start_download(link)
输出:
Enter the link of YouTube video you want to download: https://www.youtube.com/watch?v=d3D7Y_ycSms
entered
linked url
Network Connection: OK
Title: archer - danger zone [hq]
Number of views: 821439
Length of video: 11
rating of video: 4.9240561
Downloading...: 100%|#############################################| 100/100 [00:03<00:00,32.98it/s]
Done
我想将progressBar与视频下载状态集成。
预先感谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)