小编Kei*_*lly的帖子

youtube-dl 未报告正确的下载文件

我在 Python 程序中将 youtube-dl 作为模块而不是从命令行使用。它工作得很好,除了当我下载(讽刺的是)一些 YouTube 视频时 - 特别是那些音频被编码为与视频分开的文件的视频。基本上,我需要最终文件的名称,但是我在重新混合之前获得了两个文件的名称。根据 youtube-dl 文档,您可以使用钩子获取最终文件名:

文件名:最终文件名(始终存在)

tmpfilename:我们当前正在写入的文件名

似乎“文件名”应该让我得到从下载和组合的音频和视频创建的文件的名称。但它并没有这样做。

这是我的代码:

def my_hook(d):
    if d['status'] == 'finished':
    print "\nYour video has been downloaded!"
    filelocation = d['filename']
    print filelocation

def download_video(url, archival_location, asset):
    global mountpoint

    # Put Location and filename to save in a variable
    destination = archival_location + asset + ".%(ext)s"
    # options for youtubedl
    ydl_opts = {
        'logger' : MyLogger(),
        'progress_hooks': [my_hook],
        'outtmpl' : destination
    }
    try:
        # Lets download it now
        with YoutubeDL(ydl_opts) as …
Run Code Online (Sandbox Code Playgroud)

python youtube youtube-dl

5
推荐指数
0
解决办法
1571
查看次数

标签 统计

python ×1

youtube ×1

youtube-dl ×1