All Unkept
Posted in: Linux, Music, Personal and misc  —  26 June 2008

MOC and last.fm

When not using Amarok (e.g. if I'm low on memory due to using VMs or something), moc is very nice music player (Debian/Ubuntu package 'moc', but command 'mocp'). Here is how to get it to submit tracks to last.fm in a well behaved manner (that doesn't submit tracks if you are just skipping through a playlist):

  • Install lastfmsubmitd: sudo aptitude install lastfmsubmitd
  • Add yourself to lastfm group: sudo adduser [yourusername] lastfm
  • Download and save my MOC - last.fm script, and make it executable.
  • Alter your ~/.moc/config to set OnSongChange as per the instructions at the top of the script.
  • Completely quit moc and restart it.

The advantage of the script I wrote over just using OnSongChange is that my script will wait for half the length of the song before submitting to last.fm. Every 5 seconds it will check you are still listening to that song, and if not, it will quit. This way it will behave much more like Amarok and other well behaved last.fm clients.

Comments §

§ On 14 July 2008, Leonardo Bernardes wrote:
326 I didn't realize I could find something like that. Amazing script, thanks!

I just started using MOC today

§ On 22 August 2008, Skraave wrote:
351 I don't know if I'm thinking wrong, but why do you check every five seconds for the same song? Wouldn't it make sense to wait <length of song>/2 and then perform one single check?

§ On 5 September 2008, luke wrote:
353 Skraave: I wrote it that way so that if you do lots of skipping through tracks, you don't end up with hundreds of python processes -- each one will die after 5 seconds, rather than after the <length of song>/2

§ On 12 January 2009, Danny Tatom wrote:
396 I've done everything mentioned, but it won't submit to lastfm. Has this been broken since this post was made or what? :/

§ On 25 January 2009, kad1r wrote:
399 I got an error.
FATAL_ERROR: Error in config file, line 17.

§ On 17 February 2009, mythmystic wrote:
406 awesome tutorial! It works on my MOC ... i made a link to ur post from my blog i hope u dun't mind! Thx a lot...

§ On 18 August 2009, Anonymous Coward wrote:
472 2kad1r
Just update MOC

§ On 29 August 2009, surlyrider wrote:
474 Hi there. Thanks for this. I installed lastfmsubmit and added myself to the lastfm group. I put your script here: /home/surlyrider/.moc and made it executable (chmod a+x moc_submit_lastfm). You said I should edit my ~/.moc/config file but there was no 'config/ file in my ~/.moc directory, so I created one, which contains this line only: OnSongChange = "~/.moc/moc_submit_lastfm --artist %a --title %t --length %d --album %r" Anyway, it doesn't seem to be working for me. Can you think where I've gone wrong? Cheers and thanks again.

§ On 16 September 2009, avsej wrote:
483 Hi, in my moc it doesn't work too. I think that OnSongChange not fired by moc, or fired but sript missing environment and failed to start, because without this event (if i start script with proper parameters when moc is playing) it is working

§ On 8 October 2009, Vitality wrote:
494 Amazing! Thank you very much!
Ubuntu 9.04.

§ On 3 November 2009, kovtunos wrote:
502 what version of python must be installed?
now I have 2.5.4 and this script doesn't work at all :(

§ On 27 November 2009, vig wrote:
817 not working in debian squeeze

§ On 11 December 2009, Juanma wrote:
821 I follow all the steps but something goes wrong. If I alter my moc config file adding the OnSongChange line I can not run mocp. I don't know what to do with the script; I don't know where to place it and if it is necessary to be execute it everytime I run moc and want it to submit to Lastfm. Help me, please! Thank you!

Add comment

Format:

  • Javascript has to be on to get past my spam protection, and there is a delay, sorry for any inconvenience.
  • I reserve the right to moderate comments.