python 3.x - How to use Progress bar in pytube? - Stack Overflow

PHOTO EMBED

Tue Feb 22 2022 03:57:38 GMT+0000 (Coordinated Universal Time)

Saved by @baha_dev #python

from pytube import YouTube
from pytube.cli import on_progress

fuchsia = '\033[38;2;255;00;255m'   #  color as hex #FF00FF
reset_color = '\033[39m'

# url is url of youtube video to download.
def download_youtube(url):

    """ Instantiates YouTube class and downloads selected video.  Uses Built-in
    pytube.cli function on_progress to show a DOS style progress bar. """
    yt = YouTube(url, on_progress_callback=on_progress)

    # following line displays title and number of times video has been viewed. 
    print(f'\n' + fuchsia + 'Downloading: ', yt.title, '~ viewed', yt.views, 
    'times.')

    # creates download and downloads to subdirectory called 'downloads'
    yt.streams.first().download('.\\downloads\\')

    # displays message verifying download is complete, and resets color scheme 
    # back to original color scheme.
    print(f'\nFinished downloading:  {yt.title}' + reset_color)
content_copyCOPY

https://stackoverflow.com/questions/56197879/how-to-use-progress-bar-in-pytube