python - 使用 Youtube-dl 将缩略图嵌入到 mp3 引发异常

标签 python youtube-dl

我正在尝试使用 youtube-dl 将一些 youtube 视频声音下载为 mp3 并嵌入缩略图。 但每次我尝试时都会收到以下错误:

thumbnail_filename = info['thumbnails'][-1]['filename'] KeyError: 'filename'

这是我的 youtube-dl 选项

    ydl_opts = {
        'key':'IgnoreErrors',
        'format': 'bestaudio/best',
        'download_archive': self.songs_data,
        'outtmpl': '/'+download_path+'/'+'%(title)s.%(ext)s',
        'progress_hooks': [self.my_hook],
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192'},
            {'key': 'EmbedThumbnail'},]}

有什么想法吗?嵌入缩略图没有任何参数。

谢谢

最佳答案

所以我自己解决了这个问题,尽管 youtube-dl api 上没有记录它。 您需要将 'writethumbnail':True 添加到选项,并更改后处理器上的顺序,以便 'key': 'FFmpegExtractAudio' 位于 'key' 之前: '嵌入缩略图'

    ydl_opts = {
        'writethumbnail': True,
        'format': 'bestaudio/best',
        'download_archive': self.songs_data,
        'outtmpl': '/'+download_path+'/'+'%(title)s.%(ext)s',
        'progress_hooks': [self.my_hook],
        'postprocessors': [
            {'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192'},
            {'key': 'EmbedThumbnail',},]}

关于python - 使用 Youtube-dl 将缩略图嵌入到 mp3 引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38646886/

相关文章:

Python求解等式两边变量方程组

python - Youtube-dl 在 python-rq 任务中监控状态

shell - 合并视频和音频后如何删除下载的视频文件?

python - 标签 'Text_4' 在训练语料库中未见/无效

具有否定忽略模式的python copytree

python - 无法使用Python发送WhatsApp消息

python - 如何将带有字符串的 DataFrame 连接到带有 Unicode 的 DataFrame 并标准化数据类型

youtube - 如何与youtube-dl生成链接以从YouTube下载带有标题的视频?

Python - youtube-dl.utils.DownloadError : ERROR: audio conversion failed: file: mp3 invalid argument

youtube-dl 下载位置