Youtube-DL is an open source tool written in Python that helps download video and audio from Youtube and many other video streaming websites.
$ sudo apt install youtube-dl
However, the version maintained by Ubuntu tends to be old and since the Youtube website keeps changing its protocol, you might get errors downloading content.
Instead, I recommend installing the latest version using pip:
$ sudo python3 -m pip install youtube_dl
$ youtube-dl "<youtube video URL>"
Remember to enclose the URL in double quotes to avoid misinterpretation by your shell. I found that the above command downloaded the content as a MKV file.
$ youtube-dl --extract-audio "<youtube video URL>"
I found that this downloaded the audio as an Opus file.
$ youtube-dl --extract-audio --audio-format mp3 "<youtube video URL>"
I found that the created MP3 file had a VBR of 132 kbps.
$ youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 "<youtube video URL>"
I found that the created MP3 file had a VBR of 255 kbps.
--formatknob can be used to grab the best video or best audio streams for download:
$ youtube-dl --format bestvideo "<youtube video URL>" $ youtube-dl --extract-audio --format bestaudio "<youtube video URL>"
However, it seems like the tool already picks the best video or audio stream by default. I did not see any difference between the files produced with and without this knob.
Tried with: Youtube-DL 2020.07.28 and Ubuntu 18.04