How to add progress bar?

后端 未结 5 1879
逝去的感伤
逝去的感伤 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:08

    Somewhat shorter option:

    yt = YouTube(video_link, on_progress_callback=progress_function)
    
    video = yt.streams.first() # or whatever 
    
    # Prints something like "15.555% done..." 
    def progress_function(stream, chunk, file_handle, bytes_remaining):
        print(round((1-bytes_remaining/video.filesize)*100, 3), '% done...')
    

    You can, of course, limit the progress output, for instance, to values like 10, 20, 30%... - just surround the print statement with the required if-clause.

提交回复
热议问题