== morph.sh ==
Einfach mal was mit Holz machen.

Downloading all your YouTube playlists using youtube-dl - thanks to GDPR


Recently I had the idea of downloading all of my liked videos from YouTube so that I would have an archive of sorts - videos get deleted constantly, so I’d rather have them all on my own hard drive. My assumption was that I could simply do that by supplying youtube-dl with the URL of my “Liked Videos” playlist and my user credentials - and it was possible to do it that way at some point, but the good folks at Google decided to shut that down according to the internet. But as it turns out, there is an even better way: getting your playlist data via the GDPR takeout.

The YouTube menu with the 'Your data in YouTube' button

After clicking through some menus (I’m not going to bother documenting it because it probably changes very often, but it’s fairly straightforward) you can download your “Google Takeout” as either a .zip or a .tar.gz archive, as you requested. There are quite a few interesting things in there, such as your entire watch and search history, precisely documented down to the millisecond (unless you have turned this off before). I’m planning to make an analysis of these into a separate post. For now, you need the playlists directory, which should contain a bunch of CSV files. One of them is called Liked videos.csv that contains, you guessed it, the video IDs of your Liked Videos playlist along with a “Time Added” field. In order for youtube-dl to be able to download them, they have to be prefixed with https://www.youtube.com/watch?v=. This can be easily done in Excel / Calc / your favourite text editor, but there’s an extra lazy shell one-liner for Linux (or other platforms that have these tools available):

tail -n +6 "Liked videos.csv" | awk -F ',' '{ print $1 }' | sed 's/ //g' | sed 's/^/https:\/\/www.youtube.com\/watch\?v\=/' | tee to-download.txt

Having done that you can start youtube-dl in batch mode. I’ve decided to use the following command and it worked well for me:

youtube-dl --batch-file to-download.txt --write-thumbnail --write-info-json --ignore-errors --format best

write-info-json gives you a json file with all sorts of interesting metadata, and write-thumbnail does exactly what you’d expect. These two are optional but pretty handy for archiving your videos (e.g. if you want to check sometime in the future when these videos were uploaded, when you ’liked’ them etc). --ignore-errors is necessary because youtube-dl would otherwise stop at every unavailable video. If your playlist is long, those could be quite a few.