Since Youtube is such a wonderful source for all types of media – I decided to modify a script written by one of the guys at T*UG for quick and easy Youtube audio conversion for Asterisk playback (Music on hold or dial out prank goodness).
To get it going you need mplayer, sox, mpg123 and lynx (if you are using Trixbox to convert you can add the DAG repo, disable it and install the dependencies using –enablerepo=rpmforge)
So without further adieu, the script :
#!/bin/sh
echo "Downloading and converting..."
FILE=$1
URL=$2
RES=`lynx -source "$URL" | grep fullscreenUrl | cut -d'&' -f4,8` > /dev/null 2>&1
mplayer "http://www.youtube.com/get_video?$RES" -dumpaudio -dumpfile temp.mp3 > /dev/null 2>&1
mpg123 -w temp.wav temp.mp3 > /dev/null 2>&1
sox temp.wav -c 1 -r 8000 -w $FILE.wav > /dev/null 2>&1
rm temp.wav
rm temp.mp3
echo "Your file is ready - "$FILE.wav"
Usage :./script <new-file-name> <youtube-link>
You can test the audio quality by calling 425 606 3524 – this is my IPKall DID, it goes straight to Hold Music.
This sure can be a lot of fun, but remember : with great power comes great responsibility – don’t prank people you don’t know.
Have fun!



