| 30 march 2023
catdeer haven - Downloading Albums, from Youtube
So, for the geekier people out there, there's a really neat tool to
download youtube videos and do a whole bunch of fancy formatting
from the command line: `youtube-dl`. This, however, tends to break
every now and then and is slow to update. In comes `yt-dlp`, a fork
that gets more frequent updates, does some fancy User-Agent stuff
to not get throttled, and probably has some other features over
it's predecesor.
One neat function these tools have is to wrangle downloaded videos
into mp3s, even adding metadata it can find.
This is nice and all, but it only really comes together when you
realize one thing: Youtube Music is just a frontend for Youtube.
You can notice that easily by just looking at the URL when you're
viewing an album on Youtube Music: It's just a playlist, nothing
more, and `yt-dlp` can download all videos in a playlist.
However, getting all the options right for `yt-dlp` to download an
album's worth of music and add in the right metadata including the
cover art is a bit of an ordeal, considering that tool is meant to
be much more general purpose. So, I've spent a day or two getting
it mostly right:
```
yt-dlp \
--replace-in-metadata uploader ' - Topic' '' \
--parse-metadata '%(playlist_index)s:%(meta_track)s' \
--parse-metadata '%(uploader)s:%(meta_album_artist)s' \
--embed-metadata \
--embed-thumbnail --ppa "EmbedThumbnail+ffmpeg_o:-c:v mjpeg -vf \
crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\"" \
--yes-playlist --format 'bestaudio/best' --extract-audio \
--audio-format mp3 --audio-quality 0 \
--windows-filenames --force-overwrites -o \
'%(uploader)s/%(album)s/%(playlist_index)s - %(title)s.%(ext)s' \
--print '%(uploader)s - %(album)s - %(playlist_index)s %(title)s' \
--no-simulate "$@"
```
You can just stuff this overly long command into a shell script and
give it the link to a playlist (read: youtube music album) and
it'll download, convert and tag everything for you. It'll even
store everything in a neat folder structure that coincidentally is
perfect for media servers like Jellyfin: `// |