My improved youtube2mp3 converter script

A while ago I found this article http://jeffreyv.hubpages.com/hub/Youtube-to-MP3-on-Ubuntu-Linux it did exactly what it wanted at the time but me been lazy like I am decided it was time to upgrade it a bit mainly so I just need to supply it with the location URL and it names the file itself. cue investigation into youtube-dl (which is awesome) after finding that it can return the video’s title I fairly quickly got the rest sorted so here it is:

#!/bin/bash
if [ "$2" = "" ]
then
name=$(youtube-dl -s --get-title "$1")
name2=$(echo ${name} | sed -e s/"'"/""/g -e 's/ /_/g')
echo "No output file defined saving mp3 as:"
echo "/var/www/"${name2}".mp3"
Output="/var/www/"${name2}".mp3"
else
echo "Output file detected saving mp3 as:"
echo "${2}"
Output="${2}"
fi
x=~/.youtube-dl-$RANDOM-$RANDOM.flv
youtube-dl --output=$x --format=18 "$1"

ffmpeg -i $x -acodec libmp3lame -ac 2 -ab 128k -vn -y "${Output}"
rm $x