Ubuntu 16.04 上的 Youtube-dl 未将缩略图嵌入 mp3,但在使用 bash 脚本时创建了 mp3
Youtube-dl on Ubuntu 16.04 not embedding thumbnail to mp3 but creates the mp3 while using bash script
Ubuntu 16.04
Bash4.4.0
这是我的 /etc/youtube-dl.conf
--force-ipv4
--ignore-errors
--prefer-ffmpeg
--no-mtime
--add-metadata
--write-all-thumbnails
--extract-audio
--format bestaudio
--audio-format mp3
--audio-quality 0
--embed-thumbnail
--restrict-filenames
--cache-dir="/scripts/tools/youtube-dl/.cache"
-o "/scripts/tools/youtube-dl/.music-folder/%(title)s-%(id)s.%(ext)s"
这是我的错误:
[debug] System config: ['--force-ipv4', '--ignore-errors', '--prefer-ffmpeg', '--no-mtime', '--add-metadata', '--write-all-thumbnails', '--extract-audio', '--format', 'bestaudio', '--audio-format', 'mp3', '--audio-quality', '0', '--embed-thumbnail', '--restrict-filenames', '--cache-dir=/scripts/tools/youtube-dl/.cache', '-o', '/scripts/tools/youtube-dl/.music-folder/%(title)s-%(id)s.%(ext)s']
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['https://youtu.be/vXDdIp5LxLY', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2020.06.16.1
[debug] Python version 3.5.2 (CPython) - Linux-4.10.0-32-generic-x86_64-with-Ubuntu-16.04-xenial
[debug] exe versions: avconv 2.8.15, avprobe 2.8.15, ffmpeg 2.8.15, ffprobe 2.8.15
[debug] Proxy map: {}
[youtube] vXDdIp5LxLY: Downloading webpage
[youtube] vXDdIp5LxLY: Downloading thumbnail 0 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 0 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_0.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 1 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 1 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_1.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 2 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 2 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_2.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 3 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 3 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_3.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 4 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 4 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_4.webp
[debug] Invoking downloader on 'https://r1---sn-t0a7sn7d.googlevideo.com/videoplayback?expire=1594253341&ei=vQsGX9O0H_Dnhwacu6SwDA&ip=149.56.240.116&id=o-AGVfsCKujrToB5omxijFBuokRUCLyWA2-EL4f7NJyT_k&itag=251&source=youtube&requiressl=yes&mh=EX&mm=31%2C26&mn=sn-t0a7sn7d%2Csn-25ge7nsk&ms=au%2Conr&mv=m&mvi=1&pl=20&initcwndbps=360000&vprv=1&mime=audio%2Fwebm&gir=yes&clen=2241111&dur=138.701&lmt=1572877652635863&mt=1594231659&fvip=1&keepalive=yes&c=WEB&txp=1301222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAPjJRFqQeiGlZ4JnwW3xQX0GQYwYPU-Xk6uJMykuL2NgAiEAoMDPBEmu0-HrhzvxO6vTpuXby0Mp7eNS8Perq5GSlo0%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgJU0o014GQ_j22E34zlTpB6oKkJdzHAkrLK0HUWtCpksCIBVgS_CygZjM9ZaWSeolmHIorYqzVGn1qa9iGTHGsPOE&ratebypass=yes'
[download] Destination: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm
[download] 100% of 2.14MiB in 00:00
[debug] ffmpeg command line: ffprobe -show_streams file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm
[ffmpeg] Destination: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm -vn -acodec libmp3lame -q:a 0 file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3
Deleting original file /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm (pass -k to keep)
[ffmpeg] Adding metadata to '/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3'
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3 -c copy -metadata artist=MrDeepSound -metadata 'title=Low Deep T - Beautiful Things In Life' -metadata 'description=One of my favorite tracks of all time...' -metadata 'comment=One of my favorite tracks of all time...' -metadata 'purl=https://www.youtube.com/watch?v=vXDdIp5LxLY' -metadata date=20141129 file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.temp.mp3
[ffmpeg] Adding thumbnail to "/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3 -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_4.webp -c copy -map 0 -map 1 -metadata:s:v 'title="Album cover"' -metadata:s:v 'comment="Cover (Front)"' file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.temp.mp3
ERROR: Conversion failed!
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/YoutubeDL.py", line 2065, in post_process
files_to_delete, info = pp.run(info)
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/postprocessor/embedthumbnail.py", line 51, in run
self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options)
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/postprocessor/ffmpeg.py", line 235, in run_ffmpeg_multiple_files
raise FFmpegPostProcessorError(msg)
youtube_dl.postprocessor.ffmpeg.FFmpegPostProcessorError: Conversion failed!
我非常确定我的确切设置是在一年前嵌入缩略图。所以我更新了 youtube-dl 并且还安装了 python-pyxattr 和 python-xattr。我还用 pip3 安装了 youtube。
如上所示配置 /etc/youtube-dl.conf 后,我所要做的就是在脚本或命令行中发出以下命令。
youtube-dl https://youtu.be/vXDdIp5LxLY -v
正如Marco Lucidi所说,原因是嵌入不支持WEBP图像格式。
要在本地解决问题,您可以修改youtube-dl源代码中的以下文件以使其嵌入有效(检查路径):
$pip3 install --upgrade Pillow
$sudo nano /usr/local/lib/python3.8/site-packages/youtube_dl/postprocessor/embedthumbnail.py
使用以下代码(将其插入引发异常的调用之前):
# Add this code:
if thumbnail_filename.endswith('webp'):
from PIL import Image
im = Image.open(thumbnail_filename).convert('RGB')
thumbnail_filename = thumbnail_filename[:-4]+'jpg' # replace filename with the proper extention
im.save(thumbnail_filename, 'jpeg') # converts webp -> jpg
self._downloader.to_screen('[ffmpeg] ——> Converted thumbnail filename: "%s"' % thumbnail_filename)
# Put the proposed code before this existing string (line 51 in my case):
self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options)
The Pillow library 用于在各种格式之间转换图像。我添加了此代码以从经常下载的 WEBP 而非 JPG 缩略图进行转换。
Ubuntu 16.04
Bash4.4.0
这是我的 /etc/youtube-dl.conf
--force-ipv4
--ignore-errors
--prefer-ffmpeg
--no-mtime
--add-metadata
--write-all-thumbnails
--extract-audio
--format bestaudio
--audio-format mp3
--audio-quality 0
--embed-thumbnail
--restrict-filenames
--cache-dir="/scripts/tools/youtube-dl/.cache"
-o "/scripts/tools/youtube-dl/.music-folder/%(title)s-%(id)s.%(ext)s"
这是我的错误:
[debug] System config: ['--force-ipv4', '--ignore-errors', '--prefer-ffmpeg', '--no-mtime', '--add-metadata', '--write-all-thumbnails', '--extract-audio', '--format', 'bestaudio', '--audio-format', 'mp3', '--audio-quality', '0', '--embed-thumbnail', '--restrict-filenames', '--cache-dir=/scripts/tools/youtube-dl/.cache', '-o', '/scripts/tools/youtube-dl/.music-folder/%(title)s-%(id)s.%(ext)s']
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['https://youtu.be/vXDdIp5LxLY', '-v']
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2020.06.16.1
[debug] Python version 3.5.2 (CPython) - Linux-4.10.0-32-generic-x86_64-with-Ubuntu-16.04-xenial
[debug] exe versions: avconv 2.8.15, avprobe 2.8.15, ffmpeg 2.8.15, ffprobe 2.8.15
[debug] Proxy map: {}
[youtube] vXDdIp5LxLY: Downloading webpage
[youtube] vXDdIp5LxLY: Downloading thumbnail 0 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 0 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_0.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 1 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 1 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_1.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 2 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 2 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_2.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 3 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 3 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_3.jpg
[youtube] vXDdIp5LxLY: Downloading thumbnail 4 ...
[youtube] vXDdIp5LxLY: Writing thumbnail 4 to: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_4.webp
[debug] Invoking downloader on 'https://r1---sn-t0a7sn7d.googlevideo.com/videoplayback?expire=1594253341&ei=vQsGX9O0H_Dnhwacu6SwDA&ip=149.56.240.116&id=o-AGVfsCKujrToB5omxijFBuokRUCLyWA2-EL4f7NJyT_k&itag=251&source=youtube&requiressl=yes&mh=EX&mm=31%2C26&mn=sn-t0a7sn7d%2Csn-25ge7nsk&ms=au%2Conr&mv=m&mvi=1&pl=20&initcwndbps=360000&vprv=1&mime=audio%2Fwebm&gir=yes&clen=2241111&dur=138.701&lmt=1572877652635863&mt=1594231659&fvip=1&keepalive=yes&c=WEB&txp=1301222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAPjJRFqQeiGlZ4JnwW3xQX0GQYwYPU-Xk6uJMykuL2NgAiEAoMDPBEmu0-HrhzvxO6vTpuXby0Mp7eNS8Perq5GSlo0%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgJU0o014GQ_j22E34zlTpB6oKkJdzHAkrLK0HUWtCpksCIBVgS_CygZjM9ZaWSeolmHIorYqzVGn1qa9iGTHGsPOE&ratebypass=yes'
[download] Destination: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm
[download] 100% of 2.14MiB in 00:00
[debug] ffmpeg command line: ffprobe -show_streams file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm
[ffmpeg] Destination: /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm -vn -acodec libmp3lame -q:a 0 file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3
Deleting original file /scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.webm (pass -k to keep)
[ffmpeg] Adding metadata to '/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3'
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3 -c copy -metadata artist=MrDeepSound -metadata 'title=Low Deep T - Beautiful Things In Life' -metadata 'description=One of my favorite tracks of all time...' -metadata 'comment=One of my favorite tracks of all time...' -metadata 'purl=https://www.youtube.com/watch?v=vXDdIp5LxLY' -metadata date=20141129 file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.temp.mp3
[ffmpeg] Adding thumbnail to "/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.mp3 -i file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY_4.webp -c copy -map 0 -map 1 -metadata:s:v 'title="Album cover"' -metadata:s:v 'comment="Cover (Front)"' file:/scripts/tools/youtube-dl/.music-folder/Low_Deep_T_-_Beautiful_Things_In_Life-vXDdIp5LxLY.temp.mp3
ERROR: Conversion failed!
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/YoutubeDL.py", line 2065, in post_process
files_to_delete, info = pp.run(info)
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/postprocessor/embedthumbnail.py", line 51, in run
self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options)
File "/usr/local/lib/python3.5/dist-packages/youtube_dl/postprocessor/ffmpeg.py", line 235, in run_ffmpeg_multiple_files
raise FFmpegPostProcessorError(msg)
youtube_dl.postprocessor.ffmpeg.FFmpegPostProcessorError: Conversion failed!
我非常确定我的确切设置是在一年前嵌入缩略图。所以我更新了 youtube-dl 并且还安装了 python-pyxattr 和 python-xattr。我还用 pip3 安装了 youtube。
如上所示配置 /etc/youtube-dl.conf 后,我所要做的就是在脚本或命令行中发出以下命令。
youtube-dl https://youtu.be/vXDdIp5LxLY -v
正如Marco Lucidi所说,原因是嵌入不支持WEBP图像格式。
要在本地解决问题,您可以修改youtube-dl源代码中的以下文件以使其嵌入有效(检查路径):
$pip3 install --upgrade Pillow
$sudo nano /usr/local/lib/python3.8/site-packages/youtube_dl/postprocessor/embedthumbnail.py
使用以下代码(将其插入引发异常的调用之前):
# Add this code:
if thumbnail_filename.endswith('webp'):
from PIL import Image
im = Image.open(thumbnail_filename).convert('RGB')
thumbnail_filename = thumbnail_filename[:-4]+'jpg' # replace filename with the proper extention
im.save(thumbnail_filename, 'jpeg') # converts webp -> jpg
self._downloader.to_screen('[ffmpeg] ——> Converted thumbnail filename: "%s"' % thumbnail_filename)
# Put the proposed code before this existing string (line 51 in my case):
self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options)
The Pillow library 用于在各种格式之间转换图像。我添加了此代码以从经常下载的 WEBP 而非 JPG 缩略图进行转换。