[Linux] Download youtube videos from command line

Just need a script called youtube-dl, it’s already in some repositories, for example, in ubuntu you could do apt-get install youtube-dl, but it’s not always updated.

Let’s download it from source, since it’s always easy to update.

Either with curl or wget:

$ sudo curl https://yt-dl.org/latest/youtube-dl -o /usr/local/bin/youtube-dl

or wget:

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl


$ sudo chmod a+rx /usr/local/bin/youtube-dl

and that’s it.

Example: Downloading a video playlist

$ youtube-dl --extract-audio --audio-format mp3 --prefer-ffmpeg https://www.youtube.com/watch?v=flls8VaEEZc

Example: Downloading a video playlist as mp3

$ youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=flls8VaEEZc

If it give an error about avconv not being to date, you can manually update it or you could try using ffmpeg

Creating an alias

Since i only need only the music (most of times), i created an alias and appended it to $HOME/.bashrc to make it easier:

$ alias piratearmp3='youtube-dl --extract-audio --audio-format mp3 '

And use it like this:

$ piratearmp3 https://www.youtube.com/watch?v=flls8VaEEZc