Delving into Delusion

Downloading Music from Youtube with youtube-dl on Ubuntu

 May 01, 2020      Stardate: 73797.5     Tagged as: Ubuntu FFmpeg

I got bluetooth headphones for running since my old wired headphones were falling apart. I don’t need anything super-high quality since these are for running and I’ll be huffing and puffing - so I got what was available in India - JBL Endurance Dive. I currently jog with my phone playing Amazon Music, so I was going to bluetooth to my phone until I get a small bluetooth player like the SanDisk Clip Sport Plus. BUT, the JBL headphones have a built-in mp3 player with 1GB storage, so no external player needed! Of course, this is not the highest quality, but like I said I’m just running.

The next challenge is getting music for the player. I’m streaming music and don’t necessarily want to torrent. After a short time searching I found a cross-platform utility named youtube-dl.


sudo apt install youtube-dl

Now that it is installed, I recommend installing FFmpeg also. This is pretty simple, as described in this tutorial instructions. This is just a very useful utility to have and I use a bunch for transcoding video formats.

sudo apt install ffmpeg

Once you have chosen a youtube video, you can list all available audio/video formats and bitrates. Note, replace with the actual ID of the video you want. Better yet, just copy/past the entire URL.

youtube-dl -F<id>

If I run this command on the video “yYzrSGRzttk”, I see a whole list of audio and video files that are available. The first four; ID# 249, 250, 251, 140 are audio. The first three are in webm format and the last is m4a, both are optimized for delivering on the web. youtube-dl You can select the specific stream you want and download it.

youtube-dl -f 278

The better method is to let youtube-dl choose the best audio stream and download it.


youtube-dl -f bestaudio<id>

You can specify the name of the downloaded file.

youtube-dl -f bestaudio<id> --output "outputName.%(ext)s"

With FFmpeg installed, you can also convert to mp3. I know converting formats probably degrade the audio quality, but my cheap headphone mp3 player doesn’t play the webm file format.

youtube-dl -x --audio-format mp3<id>

And then finally, you can download, convert to mp3, and rename the file.

youtube-dl -x --audio-format mp3<id> --output "outputName.%(ext)s"]

Audacity to Clean Up

sudo apt install audacity


The audio files downloaded from the web probably have different loudness levels which can be undesirable. You can run a normalize and clean up batch process to all the downloaded folder.

Select “Tools > Macros…”

Audacity Macro - Normalize Levels

Make sure the macro “MP3 Conversion” is selected, then click “Files…”. This will open up a standard file browser where you can shift/select all the mp3 files you want to normalize.

Audacity Macro - MP3 Conversion

Then the magic happens! The modified files will be in a new folder named “macro-output”.

Software Versions

This is an automated list of software versions used during the writing of this article.

OS Ubuntu 20.04 LTS
youtube-dl 2020.03.24
Audacity 2.3.3