MOC now playing lyrics script

hakerdefo

I've this script that fetches lyrics of currently playing song in MOC and displays it in terminal,


#!/bin/sh
TITLE="`mocp -i | grep 'Title:' | sed -e 's/^.*: //'`";
if [ "$TITLE" != "" ]; then
ARTIST="`mocp -i | grep 'Artist:' | sed -e 's/^.*: //'`";
SONGTITLE="`mocp -i | grep 'SongTitle:' | sed -e 's/^.*: //'`";
ALBUM="`mocp -i | grep 'Album:' | sed -e 's/^.*: //'`";
if [ "$ARTIST" != "" ]; then ARTIST="$ARTIST"; fi
if [ "$ALBUM" != "" ]; then ALBUM="($ALBUM)"; fi
#echo $ARTIST $SONGTITLE $ALBUM
#else echo ,,MOC"
#fi
artist=`echo "$ARTIST" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'`
title=`echo "$SONGTITLE" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"'`
song=`curl -s "http://makeitpersonal.co/lyrics?artist=$artist&title=$title"`
echo "$SONGTITLE - $ARTIST - $ALBUM\n$song" | less
else echo ,,MOC"
fi


It works fine most of the time but fails in some instances when a song tag or artist tag contains some extra characters.
Any ideas to parse tags more efficiently and make them more url friendly?
Cheers.
You Can't Always Git What You Want