【问题标题】:Pytube : How to add the parameters for function progress_CheckPytube:如何为函数progress_Check添加参数
【发布时间】:2021-11-03 02:37:58
【问题描述】:
def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None):
    global file_size
    #Gets the percentage of the file that has been downloaded.
    percent = (100*(file_size-remaining))/file_size
    print("{:00.0f}% downloaded".format(percent))

调用上述函数返回下载百分比时

yt = YouTube(link,on_progress_callback=progress_Check)

但我得到一个错误,比如不能减去整数和无,那么函数参数是什么/如何获取它们?

有什么想法吗??

【问题讨论】:

    标签: python pytube


    【解决方案1】:

    progress_Check 只需要 3 个参数:streamchunkremaining

    由于只需要 3 个参数,因此第 4 个参数没有分配给任何东西,因此 remaining 将被设置为 None 并在计算过程中导致错误

    您也不需要将每个参数的默认值设置为 None,因为无论如何这些都会被覆盖

    这是固定代码:

    def progress_Check(stream, chunk, remaining):
        global file_size
        #Gets the percentage of the file that has been downloaded.
        percent = (100 * (file_size - remaining)) / file_size
        print("{:00.0f}% downloaded".format(percent))
    

    【讨论】:

    • 谢谢兄弟,这行得通。但它只提供 100% 的输出(下载完成时),并且在下载过程中不提供任何输出。如何解决?
    • 这只是意味着下载速度非常快,如果下载需要更多时间,它会显示较低的百分比
    猜你喜欢
    • 2020-09-14
    • 1970-01-01
    • 2020-03-25
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2017-05-21
    • 1970-01-01
    相关资源
    最近更新 更多