问题是因为pbar.update()
期望值current_received - previous_received
download
只给出current_received
,所以你必须使用一些变量来记住以前的值并减去它
最小的工作代码:
import pafy
import tqdm
# --- functions ---
previous_received = 0
def update(pbar, current_received):
global previous_received
diff = current_received - previous_received
pbar.update(diff)
previous_received = current_received
# --- main ---
v = pafy.new("cyMHZVT91Dw")
s = v.getbest()
video_size = s.get_filesize()
print("Size is", video_size)
with tqdm.tqdm(desc="cyMHZVT91Dw", total=video_size, unit_scale=True, unit='B', initial=0) as pbar:
s.download(quiet=True, callback=lambda _, received, *args:update(pbar, received))