Как использовать Progress bar в pytube? - PullRequest
0 голосов
/ 18 мая 2019

Я хочу реализовать индикатор прогресса в моем коде, но ни старый, ни новый способ реализации не работает.

Как добавить индикатор выполнения? это исправление не работает в последней версии.
Вот последняя документация https://pypi.org/project/pytube/

from pytube import YouTube
url="https://youtu.be/J5EXnh53A1k"
path=r'D://'
yt = YouTube(url)
yt.register_on_progress_callback(show_progress_bar)#by commenting this line code works fine but no progress bar is displyed
yt.streams.filter(file_extension='mp4').first().download(path)


def show_progress_bar(stream, _chunk, _file_handle, bytes_remaining):
  current = ((stream.filesize - bytes_remaining)/stream.filesize)
  percent = ('{0:.1f}').format(current*100)
  progress = int(50*current)
  status = '█' * progress + '-' * (50 - progress)
  sys.stdout.write(' ↳ |{bar}| {percent}%\r'.format(bar=status, percent=percent))
  sys.stdout.flush()

1 Ответ

0 голосов
/ 14 июня 2019

Я использую прогрессбар2

def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None):

        percent = file_size - remaining + 1000000   

        try: 
            # updates the progress bar                                   
            bar.update(round(percent/1000000,2))
        except: 
            # progress bar dont reach 100% so a little trick to make it 100    
            bar.update(round(file_size/1000000,2))

yt = YouTube(url, on_progress_callback=progress_Check)
yt = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()
...