
How I use YT-DLP for my offline music library
A friend of mine recently asked me how I download music and instead of simply answering him like any sane person would do, I decided to write a guide on it.
Disclaimer: I only download music I already own a physical copy of, and encourage everyone to support your favorite artists by any means you can.
Why do I download music?
For almost 5 years I’ve been a loyal Spotify customer and had little to no complaints about the service.
I felt good supporting the people I love to listen to and as I had a student discount on my subscription, it was a great deal for me.
The thing is that as time went on some things changed:
- I discovered how little Spotify pays out to artists.
- I found out about the company supporting Palantir (if you know, you know).
- The music I got recommended by the app was mostly music I already had in a playlist or had listened before, so I didn’t get any real value in terms of discovering new songs.
- The price increase as my student discount expired (even though I was still an active university student).
Considering all of the above and after thinking it for quite some time I decided to cancel the subscription.
Installing YT-DLP
In my case, as I’m using an arch based distro, it was easier to install it using pacman like so:
sudo pacman -Syu yt-dlp
Installing it this way has the advantage of getting updates every time I update my system instead of having to manually update yt-dlp whenever I go to use it.
This tool relies on FFMPEG so you will need to install it as well. For other methods of installing YT-DLP, you can check out the official wiki.
Using YT-DLP
This tool is primarily used in the terminal (although there are a few frontend apps that may be of your interest). The basic usage is quite straightforward:
yt-dlp [OPTIONS] [--] URL [URL...]
To see every single option you have you can simply run: man yt-dlp in the terminal or refer to the documentation.
To avoid having to type every option you want every single time you want to download a video, you can modify the configuration file that gets used by the tool.
This file gets created automatically when you first install the app and the location depends on what system you are using,
in my case its located at ~/.config/yt-dlp/config.
The configuration file has no extension and you just need to enter the options you want yt-dlp to follow when using it.
This is the configuration I use:
# Extract only audio
-x
# Format audio to m4a at 128kbps
--audio-format m4a
--audio-quality 128K
# Add metadata and cover art
--embed-metadata
--embed-thumbnail
# Avoid downloading as playlist
--no-playlist
# Output file template
-o "%(artist)s - %(title)s.%(ext)s"
# Extract browser cookies to resolve youtube js challenges
--cookies-from-browser firefox
# Try to skip adds for non-premium accounts
--extractor-args "youtube:use_ad_playback_context=true"
# Ignore errors and continue downloading
-i
# Enable node.js
--js-runtimes node
This is how I personally like to download my music as I’m not an audiophile and prioritize having files that occupy little space.
After modifying the config file I don’t need to give yt-dlp any options when using it, so I can just run yt-dlp [URL] with no arguments.
cd Music
cd "Rick Astley"
yt-dlp https://www.youtube.com/watch?v=dQw4w9WgXcQ
This will download the song to a folder named “Rick Astley” in the “Music” directory, with all the options above.
You can also use it to download playlists and not only from Youtube, in fact, I normally download complete albums from Youtube Music like so:
yt-dlp https://music.youtube.com/playlist?list=OLAK5uy_mHRRlmPfQMHbRoomid03FuXIMZ-O_hW58
This will download every song in the album individually to the folder you are currently working on, and in case a song is repeated, yt-dlp will automatically skip the song keep downloading the rest.