I have modified this script to download songs from YouTube but I am getting the following error when I run it like this:
sh youtube2mp3.sh https://www.youtube.com/watch?v=gpOJ6iu8fqQ
Errors:
youtube2mp3.sh: line 31: [: too many arguments
youtube2mp3.sh: line 39: [: too many arguments
youtube2mp3.sh: line 49: [: too many arguments
Sorry but the system encountered a problem.
The line numbers are referring to the three if [ -f $video_title.$ext1 ]
lines ... I thought I had the arguments ok as it worked in a previous version, but I'm stuck at this point — could someone explain what I need to do to correct it?
address=$1
video_title="$(python youtube-dl $address)"
ext1="flv"
ext2="mp4"
ext3="webm"
if [ -f $video_title.$ext1 ]
then
ffmpeg -i $video_title.$ext1 "$video_title".wav
lame "$video_title".wav "$video_title".mp3
rm $video_title.$ext1 "$video_title".wav
else
if [ -f $video_title.$ext2 ]
then
ffmpeg -i $video_title.$ext2 "$video_title".wav
lame "$video_title".wav "$video_title".mp3
rm $video_title.$ext2 "$video_title".wav
else
if [ -f $video_title.$ext3 ]
then
ffmpeg -i $video_title.$ext3 -acodec libmp3lame -aq 4 "$video_title".mp3
rm $video_title.$ext3
else
echo "Sorry but the system encountered a problem."
fi
fi
fi