Introducing WebP Thumbnail Support
Struggling with the new WebP thumbnail format on YouTube? The improved YouTube2Audiobook has all you need! Readily available on GitHub.
An Abundance of Audiobooks
When it comes to great audiobooks, YouTube really can be an abundant source. A fair amount of the (un)read books on My Reading List are actually available on the platform.
From millennia-old classics to modern works, there is an ever growing guild of like-minded enthusiasts recording these works as audiobooks and providing them to the world, free of charge. As of 2020-10-08, the great LibriVox Audiobooks channel alone already features over 17,600+ complete audiobooks and 1,300+ playlists.
The YouTube2Audiobook app allows me to tap into this vast resource, scale out my reading, and expand my horizon. The recently introduced playlist support for YouTube2Audiobook accelerates this even further.
I can now download every video in the above “Author: Sir Arthur Conan DOYLE playlist” from the LibriVox Audiobooks channel as an audiobook by simply typing
$ yt2ab -u "https://www.youtube.com/playlist?list=PLZ-bKJtH3G7BKcrVgIZfVNIAZTtsnIJg-"
into a terminal of my choice (it’s iTerm2, in case you’re curious). And the Sherlock Holmes audiobooks will appear one after another. Slowly. But steadily. In order to not get throttled or blocked by the platform.
A New Thumbnail Image Format
However, that’s not entirely true. Unfortunately. When issuing the above yt2ab
command, the actual output is the much rather disappointing
$ yt2ab -u "https://www.youtube.com/playlist?list=PLZ-bKJtH3G7BKcrVgIZfVNIAZTtsnIJg-"
Processing https://youtu.be/UzzubzBE3kg: 'The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various | Full Audio Book'...
[youtube] UzzubzBE3kg: Downloading webpage
[youtube] UzzubzBE3kg: Downloading thumbnail ...
[youtube] UzzubzBE3kg: Writing thumbnail to: The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4.webp
[youtube] UzzubzBE3kg: Downloading webpage
[download] Destination: The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4-youtube-audio.mp3
[download] 100% of 420.69MiB in 00:51
[ffmpeg] Correcting container in "The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4-youtube-audio.mp3"
[ffmpeg] Post-process file The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4-youtube-audio.mp3 exists, skipping
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4-youtube-audio.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.45.100
Duration: 10:18:08.05, start: 0.000000, bitrate: 94 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 93 kb/s (default)
Metadata:
handler_name : SoundHandler
The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4.jpg: No such file or directory
So, YouTube2Audiobook is failing at the FFmpeg stage where it is converting the downloaded audio to an Mp3 file while at the same time also adding the previously downloaded thumbnail.
And therein lies the problem. In the above case, there is no thumbnail by the (expected) name The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various _ Full Audio Book-UzzubzBE3kg.mp4.jpg
. How come…?!
Well. Historically, thumbnails were predominantly served by the platform as JPEG files. Until, in 2014, YouTube announced its move to the more efficient WebP format for it’s highest resolution thumbnails.
The effect of this move can actually be observed for the very first video in the above playlist (the one you see in the embedded YouTube player). When requesting a list of all corresponding thumbnails for the first video, it actually returns five of them.
$ youtube-dl --list-thumbnails https://youtu.be/UzzubzBE3kg
[youtube] UzzubzBE3kg: Downloading webpage
[info] Thumbnails for UzzubzBE3kg:
ID width height URL
0 168 94 https://i.ytimg.com/vi/UzzubzBE3kg/hqdefault.jpg?sqp=-oaymwEYCKgBEF5IVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLDti8Hb-liUchAf-MU0Xr9HAPCxJw
1 196 110 https://i.ytimg.com/vi/UzzubzBE3kg/hqdefault.jpg?sqp=-oaymwEYCMQBEG5IVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLAFktUb_j_TvUWRLCwGOIX8pKUM2A
2 246 138 https://i.ytimg.com/vi/UzzubzBE3kg/hqdefault.jpg?sqp=-oaymwEZCPYBEIoBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLAEXWWhCRiC4Xkm8J5AmBnHEZkG0A
3 336 188 https://i.ytimg.com/vi/UzzubzBE3kg/hqdefault.jpg?sqp=-oaymwEZCNACELwBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLB7QJOLD80Y2J7wCMONRutgMQBPWQ
4 1920 1080 https://i.ytimg.com/vi_webp/UzzubzBE3kg/maxresdefault.webp
Here, the largest thumbnail is indeed a WebP file, hopefully correctly displayed by your browser below (click here if you want to open it in a separate window).
![The Adventures of Sherlock Holmes by Sir Arthur Conan DOYLE read by Various | Full Audio Book - Thumbnail](https://i.ytimg.com/vi_webp/UzzubzBE3kg/maxresdefault.webp) |
The above image should match the image you see in the embedded YouTube player above; it’s what it uses under the covers.
An Unpredictable File Name
So, why does this matter exactly? Well, the underlying youtube-dl
open source project has a quirky behaviour when it comes to writing thumbnail files.
As of 2020-10-08, when told to write the thumbnail to file cover.jpg
, via optional parameters, the output may actually be written to file cover.webp
in case YouTube returns a WebP file; this can also be seen in below output
$ youtube-dl --write-thumbnail --skip-download -o cover.jpg https://youtu.be/UzzubzBE3kg
[youtube] UzzubzBE3kg: Downloading webpage
[youtube] UzzubzBE3kg: Downloading thumbnail ...
[youtube] UzzubzBE3kg: Writing thumbnail to: cover.webp
So, the name of the thumbnail file basically isn’t fixed (which it should be, in my humble opinion) but rather depends on what YouTube returns it on that specific day.
Moreover, I am not aware of a reliable way of extracting the name of the downloaded thumbnail file via the return values provided by youtube-dl
. Please feel free to send me an email, in case I have missed something.
Asking for Forgiveness
However, this can be dealt with. Rather than checking for the last modified file, which can introduce race conditions and eventually prohibits scaling, it’s possible to work with the reality of the YouTube ecosystem.
As most thumbnails on YouTube for a video with title
title
are still in JPEG format, it’s a sensible guess to request to save the thumbnail to filetitle.jpg
. If that’s the case,youtube-dl
will write the file as intended. If the thumbnail is not in JPEG format, thenyoutube-dl
will save it totitle.EXTENSION
whereEXTENSION
is the extension returned by the sever. In the latter case bet on it being a WebP file saved to filetitle.webp
. In all other cases ask for forgiveness, as the thumbnail is in an unknown file format.
This solution has been fully integrated into the latest version of YouTube2Audiobook. This closes bug “Add WebP Thumbnail Support” and was addressed in commit 3215586.
So, How do You Handle WebP Images?!
While the above Worx for Me!™ when it comes to handling WebP video thumbnails in YouTube2Audiobook, you may have an alternative or better way.
Feel free to leave a comment or contribute to the GitHub repository, so we can make things better for everyone! A big thank you to everyone who did already contribute! Think this is all rubbish, incomplete, massively overcomplicated, or simply the wrong tool for the job?! Reach out to me on LinkedIn and teach me something new!
As always, prove me wrong and I’ll buy you a pint!
Subscribe to How Hard Can It Be?!
Get the latest posts by following us on LinkedIn and Twitter