Python Pytube如何添加进度条?
我不知道该怎么做,每当我尝试从其他话题解决这个问题时,我都会出错。 主要类型错误:显示进度条缺少1个必需的位置参数:“剩余字节”Python Pytube如何添加进度条?,python,pytube,Python,Pytube,我不知道该怎么做,每当我尝试从其他话题解决这个问题时,我都会出错。 主要类型错误:显示进度条缺少1个必需的位置参数:“剩余字节” from pytube import YouTube #took this def from another topic def progress_function(stream, chunk, file_handle, bytes_remaining): percent = round((1-bytes_remaining/video.filesize)*
from pytube import YouTube
#took this def from another topic
def progress_function(stream, chunk, file_handle, bytes_remaining):
percent = round((1-bytes_remaining/video.filesize)*100)
if( percent%10 == 0):
print(percent, 'done...')
url = "Any youtube url"
yt = YouTube(url, on_progress_callback=progress_function)
yt.streams[0].download()
例如,当我运行这个精确的代码时,它会给我那个错误
我真的无法理解它的逻辑。我还搜索了PYTube 3网站上的文档,但我无法解决这个问题。请帮帮我。谢谢。删除流,它就会工作,最近我试图开发类似的逻辑,但遇到了类似的错误
以下是对我有用的代码:
def progress(chunk, file_handle, bytes_remaining):
global filesize
remaining = (100 * bytes_remaining) / filesize
step = 100 - int(remaining)
print("Completed:", step) # show the percentage of completed download
选择要下载的视频或音频后,可以检索文件大小,例如
yt = YouTube(str(link), on_progress_callback=progress) # Declare YouTube
yt1 = yt.streams.get_by_itag(int(itag)) # itag is given when you list all the streams of a youtube video
filesize = yt1.filesize
希望这有帮助 可能会使用如下内容:def progress\u test*argv:printargv进行调试。听起来它向函数传递了3个参数,而不是4个,这将证明它传递给自定义进度函数的参数有多少。它给出了关于第四个参数的错误,该参数为字节。\u remaining那么您可以删除该参数吗?事实上是的,当我删除它时,打印的其他参数没有错误。谢谢你的技巧。