This entry is part 4 of 19 in the Bash-whacking series

For Ubuntu..

sudo apt-get install ffmpeg

cd ~/bin
wget https://github.com/rg3/youtube-dl/raw/2010.11.19/youtube-dl
chmod +x youtube-dl

wget http://www.supermind.org/scripts/youtube2mp3
chmod +x youtube2mp3

 

The contents of youtube2mp3 is simple:

#!/bin/bash
#!/bin/bash

x=/tmp/.youtube-dl-$RANDOM-$RANDOM.flv
youtube-dl –output=$xformat=18 "$1"
ffmpeg -i $x -vn -ar 44100 -ac 2 -ab 256k -f mp3 "$2"
 

Now get the youtube URL you want to convert to MP3, and run it like so:

youtube2mp3 <youtube_url>
 

For example:

youtube2mp3 http://www.youtube.com/watch?v=cFhaBEtmHeU