elias
elias

Reputation: 31

Showing progress in pytube

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 :)

Upvotes: 3

Views: 5094

Answers (2)

mouhamed Mouhamed
mouhamed Mouhamed

Reputation: 1

from 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/")

Upvotes: -1

Pratham Kalgutkar
Pratham Kalgutkar

Reputation: 71

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()

Upvotes: 7

Related Questions