在 pytube 中显示进度 [英] Showing progress in pytube

查看:39
本文介绍了在 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()

这是我最近制作的一个脚本,用于使用 pytube 从 youtube 下载视频和音频文件,但我很难尝试添加一个功能或可以向用户显示下载进度的内容.即:1% 完成 2% 完成等任何帮助将不胜感激:)

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

推荐答案

这是我的第一次回答,为错误道歉.

This is my First Time Answering, apologizes for mistakes.

阅读 Pytube 文档,可能会注意到 pytube 有 this 选项已作为进度条实现,您需要在 YouTube 对象中调用 on_progress_callback.

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

这篇关于在 pytube 中显示进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆