我正在尝试使用 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/