Author Topic: MOC now playing lyrics script  (Read 3123 times)


  • Posts: 525
    • View Profile
    • Looking at Linux through the Windows of Life
MOC now playing lyrics script
« on: January 24, 2014, 10:38:55 AM »
I've this script that fetches lyrics of currently playing song in MOC and displays it in terminal,

Code: [Select]
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
#else echo „MOC”
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 "$artist&title=$title"`
echo "$SONGTITLE - $ARTIST - $ALBUM\n$song" | less
else echo „MOC”

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?
You Can't Always Git What You Want