[script] moc-lyrics: Fetches lyrics of current song playing in moc music player.

Forums:

A little bash script to get the lyrics of currently playing song. perl and curl are the only two dependencies. Save the script somewhere in your path with the name 'moc-lyrics' and give it permission to execute. Enter moc-lyrics in your terminal and it will show you the lyrics of current moc song. I've created a GitHub repo as well. You can check it out for any updates and/or detailed installation instructions,
https://github.com/hakerdefo/moc-lyrics
Here is the script,

#!/bin/sh

MOCSTATE=$(pgrep mocp)

if [[ -z "$MOCSTATE" ]]; then
echo "MOC Is Not Running!"
exit
fi

SONGTITLE=$(mocp -i | grep 'SongTitle:' | sed -e 's/^.*: //');
ARTIST=$(mocp -i | grep 'Artist:' | sed -e 's/^.*: //');
ALBUM=$(mocp -i | grep 'Album:' | sed -e 's/^.*: //');

if [[ -z "$SONGTITLE" ]]; then
echo "MOC Is Not Playing Anything!"

else

title=$(echo "$SONGTITLE" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
artist=$(echo "$ARTIST" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
song=$(curl -s "http://makeitpersonal.co/lyrics?artist=$artist&title=$title")

printf "$SONGTITLE - $ARTIST - $ALBUM\n$song" | less
fi

Cheers!!!

MOC has an included basic lyric-handling system. If you would make your script to write lyrics to a file, then you could bind it to F1 key by "ExecCommand1" config option. Then you would be able to display lyrics in MOC client by pressing "L".

In that case, you don't have to parse "mocp -i" for song details, MOC can pass it as command-line options.

There is also another script you might play with to do the job - you can find it in the contrib section: http://moc.daper.net/contrib It can be used within MOC but it doesn't save the file. I have modified it slightly to save a lyrics file, I can send it to you if you wish.

However I think that MOC internal lyrics mechanism is flawed, and I intend to develop a patch to make it better. I have done some initial work, but I didn't finish it yet. Some discussion can be found e.g. here http://moc.daper.net/node/897

It would be great if you can send me the modified version of the script you mentioned. You can mail it to me at, hakerdefo at gmail dot com
It shouldn't be difficult to make my script save the lyrics. I didn't know about built-in lyrics viewer of MOC. I'll try and modify the script and will share it here.
Cheers!!!