Someone might really want to keep their favourite YouTube videos forever. For this, said someone might use a youtube-dl
fork called yt-dlp
. In this fictional scenario imagine that “I” employ this method of downloading YouTube videos.
Like the original it has lots of options and as of the writing of this post it gets regular updates. To get it all working on macOS the installation is easy enough using homebrew: brew install yt-dlp
. You will also need ffmpeg installed.
The real difficulty was trying to figure out how to get the best video and audio in a format that ist compatible on basically all my devices and – most importantly – my Plex server.
Without going into the discovery process, which involved some trial and error (being a lame script kiddie in that regard…) I found what works best for my use case. So, without any further delay, this is what I use:
yt-dlp -v --merge-output-format "mp4/mkv" -o "/Volumes/Mediathek/youtube-dl/YT-Fav-Archive/%(upload_date)s - %(release_date)s - %(channel)s - %(title)s - %(id)s.%(ext)s" -i -f 'bestvideo+bestaudio' --download-archive /Volumes/Mediathek/youtube-dl/YT-Fav-Archive/archive.txt "https://www.youtube.com/playlist?list=[PLAYLIST ID]"
-v
just creates a verbose output for troubleshooting and curiosity reasons.--merge-output-format "mp4/mkv"
specifies the containers that may be used for the output file. I allow mp4 and mkv.-o
just specifies the output file.
What follows inside the quotation marks ist just the path to my Synology share with a specification of the file name, which is pretty self explanatory. %(id)s
is the YouTube video ID.-i
specifies to continue on download errors (e. g. skipping unavailable videos)-f
specifies the output format being 'bestvideo+bestaudio'
. yt-dlp should try to get the best video and audio on its own, but for some reason I wrote this to my text file ages ago. Suspecting I might have had a reason – and this works – I keep copying everything into the terminal.--download-archive
is the really awesome feature: yt-dlp writes all successfully downloaded videos to the specified text file. Next time you run it against the same playlist, all video IDs in this file get skipped. This way only new videos in the playlist get downloaded."https://www.youtube.com/playlist?list=[PLAYLIST ID]"
then just is the URL to the playlist.
But isn’t a Favourites playlist private and only for my account to see?
Someone who might ask
It should be possible to use YouTube credentials and some type of cookie wizardry to log in and authenticate use of the playlist. I had some trouble logging into Youtube with yt-dlp, so I decided it’s not worth my time and fell back to a – for me – reasonably okay solution: The Playlist gets to be public for the duration of the download.
Unfortunately, the Favourites playlist can’t be just unlisted, it has to be either private or public.
What happens when your press enter after all of that is amazing:
yt-dlp downloads the video and audio files in their respective best available quality. After both files are saved to disk, yt-dlp invokes ffmpeg to package everything neatly into a matroska file. The temporary separate video and audio files are then deleted.
And in the end everything is saved, named correctly and forever mine in my favourites archive.