How to add progress bar?

后端 未结 5 1881
逝去的感伤
逝去的感伤 2020-12-21 02:22

Is there a way to add progress bar in pytube? I don\'t know how to use the following method:

pytube.Stream().on_progress(chunk, file_handler, bytes_remaining         


        
5条回答
  •  抹茶落季
    2020-12-21 03:13

    from pytube import Playlist
    from pytube import YouTube
    
    previousprogress = 0
    def on_progress(stream, chunk, bytes_remaining):
        global previousprogress
        total_size = stream.filesize
        bytes_downloaded = total_size - bytes_remaining 
    
        liveprogress = (int)(bytes_downloaded / total_size * 100)
        if liveprogress > previousprogress:
            previousprogress = liveprogress
            print(liveprogress)
    
    
    yt = YouTube('https://www.youtube.com/watch?v=4zqKJBxRyuo&ab_channel=SleepEasyRelax-KeithSmith')
    yt.register_on_progress_callback(on_progress)
    yt.streams.filter(only_audio=True).first().download()
    

提交回复
热议问题