3
import pytube
def video_downloader():

    vid_url=str(input("Enter Video URL: "))
    print('Connecting, Please wait...')
    video=pytube.YouTube(vid_url)
    Streams=video.streams
    File_name=input('File Name:')
    Format=input('Audio Or Video :')

    if Format=='Audio':
        Filter=Streams.get_audio_only(subtype='mp4')
    if Format=='Video':
        Filter=Streams.get_highest_resolution()
    print('Now downloading:',video.title)
    sizer=round(Filter.filesize/1000000)
    print('Size:',sizer,'MB')


    Filter.download(filename=str(File_name))
    print('Done!')
video_downloader()

This is a script I've made recently to download video and audio files from youtube using pytube, but I'm having a hard time trying to add a function or something that could show the user the progress of the download. i.e: 1%complete 2%complete etc Any help would be appreciated :)

elias
  • 31
  • 1
  • 2

2 Answers2

7

This is my First Time Answering, apologizes for mistakes.

Reading Pytube Documentation, one may notice that pytube have this option already implemented as a Progress Bar, You will need to call on_progress_callback in your YouTube Object.

from pytube.cli import on_progress
from pytube import YouTube

yt = YouTube(video_url, on_progress_callback=on_progress)
yt.download()
0

pytubeenter code herefrom pytube.cli import on_progress

from pytube import YouTube as YT

yt =YT ("https://",on_progress_callback=on_progress)

yt.streams.get_highest_resolution().download(output_path="/Users/")

↳ |██████████████████ | 17.

  • Could you edit this answer to explain this code, how it addresses the question, and how it improves upon the existing answer? – memtha Sep 30 '21 at 03:27
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 30 '21 at 06:00