Back to blog
Sep 2019·1 min readAI-translated

Youtube-DL Download MP3 (fast!)

#download#fast#kurzversion#link#mp3#youtube-dl

For some time now I've been using the wonderful tool youtube-dl. If you don't know it: it lets you download videos, music and more from many sites. Its feature set is broad, but most of the time I only need the MP3 version and not an MKV, WEBM or MP4 variant. That works with the wonderfully memorable command

youtube-dl -x --audio-format mp3 --audio-quality 0 "LINK"

easy to remember, right? Of course that got too "clunky" for me in the long run. Something like this would be simpler:

youtube-dl-mp3 LINK

That's easy to achieve by passing the link on to youtube-dl through a small function:

1. Edit .bash_profile

You edit your .bash_profile. To do that, open the console and type

nano ~/.bash_profile

(if it doesn't exist yet, it will be created). If you don't have nano installed, you can (surprise!) simply install it, or use vi. Add the following line:

source "/Users/$USER/.bash_functions"

The .bash_profile is loaded and executed every time the console starts. "source" extends this file (= loads another file), which in our case is ".bash_functions".

2. Create .bash_functions

To do that, type the following into the console (again):

nano ~/.bash_functions

and add the following line

youtube-dl-mp3() { youtube-dl -x --audio-format mp3 --audio-quality 0 "$1"; }

Your console now knows the command youtube-dl-mp3, which takes the URL of the video as a parameter and starts youtube-dl with that URL.

3. Reload .bash_profile

Finally you need to reload the changed bash_profile. This is done with the command

source ~/.bash_profile

Alternatively, you can simply restart the console.

4. Test it!

Lastly, test the whole thing by typing the following command into the terminal:

youtube-dl-mp3 LINK

(replace LINK with a link to a video, audio or similar, of course) and lo and behold: the download runs simply and effectively as an MP3 file.

NewerNASA - Visualizing Elevation DataOlderBrute Force Protection