another script for moc - status and song change

Hello there,

I wrote a little perl script called mocstat that implements some kind of song change and general status information functionality. It runs in the background and invokes continuously (every 500ms) "mocp --info". The gathered status information will be submitted to two scripts via environment variables.

  • ~/.mocstat/update is called every time "mocp --info" is called.
  • ~/.mocstat/songchange is called when the current song has been playing for 30 seconds.

[br]

Here is an example for ~/.mocstat/update:

#!/bin/sh
echo -e "$TITLE" > ~/.conky/mocstat.title
echo -e "$CURRENTTIME" > ~/.conky/mocstat.currenttime
echo -e "$TOTALTIME" > ~/.conky/mocstat.totaltime
echo -e "$PERCENTDONE" > ~/.conky/mocstat.percentdone

This puts the status information in some FIFOs which I can read in my conkyrc via ${exec cat ~/.conky/mocstat.title} or ${execbar cat ~/.conky/mocstat.percentdone} or something like this.
I use FIFOs because normal files are sometimes empty when conky reads them which makes the display flickering. By using a FIFO, conky hangs until there is something to read. (Create a FIFO with mknod or mkfifo.)

[br]

Here is an example for ~/.mocstat/songchange to scrobble your music to last.fm via lastfmsubmitd:


#!/bin/sh
if [ -n "$ARTIST" ] && [ -n "$SONGTITLE" ] && [ -n "$TOTALTIME" ]; then
/usr/lib/lastfmsubmitd/lastfmsubmit --encoding UTF-8 --artist "$ARTIST" --title "$SONGTITLE" --length "$TOTALTIME" --album "$ALBUM"
fi

If the necessary information for scrobbling (artist, title and length) is available, submit it to lastfmsubmitd which will make sure it gets to last.fm.

[br]

When you run this script for the first time, it creates ~/.mocstat/ automatically. You can then create and edit ~/.mocstat/update and/or ~/.mocstat/songchange. And don't forget to make them executable.

I put mocstat & in my ~/.xsession, so it gets started when I log in and works silently in the background.

And finally the download link: http://www.sendspace.com/file/hypep2

Feel free to send any constructive feedback to fagga@gmx.de.

Forums:

Nice solution until running external scripts by MOC on events will appear. I see the script properly handles it's restart without losing it's state.

--
Damian Pietras - MOC developer

I submitted a patch that calls an executable with some escapable arguments on song change. After we get any bugs/style stuff ironed out (i.e. soon), it'll be in SVN.

The download link is gone, please repost :)

I re-uploaded the script, but nobody knows when the link will be dead again. Does anyone know a good free file hosting provider? Or maybe it could be stored somewhere on this site?

Here is the new download link:
http://z05.zupload.com/download.php?file=getfile&filepath=10333

I should have done this long before but here it is:
http://moc.daper.net/contrib

--
Damian Pietras - MOC developer

how do you run the script?