Update: people are having trouble with this now, I am unable to debug what is wrong, it seems like a problem with mocp.
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 §
I just started using MOC today
FATAL_ERROR: Error in config file, line 17.
Just update MOC
Ubuntu 9.04.
now I have 2.5.4 and this script doesn't work at all :(
I did exactly everything you've said and it's not working. The bottom of my config file looks like this:
OnSongChange = "~/.moc/moc_submit_lastfm --artist %a --title %t --length %d --album %r"
And it does nothing.
--- moc_submit_lastfm.orig 2008-06-27 00:40:38.000000000 +0200
+++ moc_submit_lastfm 2010-02-19 09:41:23.000000000 +0100
@@ -33,7 +33,7 @@
p = Popen(["mocp", "-i"], stdout=PIPE)
out, err = p.communicate()
lines = out.split("\n")
- for s in ["Artist: %s" % artist, "Album: %s" % album, "SongTitle: %s" % title]:
+ for s in ["State: PLAY", "Artist: %s" % artist, "Album: %s" % album, "SongTitle: %s" % title]:
if not s in lines:
return False
return True
The last thing I did before it started working was to switch the order of 2 lines in "/etc/lastfmsubmitd.conf".
In the INSTALL doc, it says the file should look like:
[account]
username = WaltKelly
password = amondayfriday13
Mine looked like:
[account]
password = amondayfriday13
username = WaltKelly
I don't know if switching it back to how INSTALL describes it fixed my problem or if it was that I gave myself ownership privileges to the files INSTALL lists. In any event, last.fm now reflects my recent moc plays.
After specifying the right config file, I saw a few other places things could go weird, not sure if they'll fix anything, but;
1. Like eleventhcrane said, check the order in /etc/lastfmsubmitd.conf
2. Make sure MOC is using the right MOCDir/config file
3. Make sure that OnSongChange doesn't have the default "/path/to/file" thing!
Not sure if it's working for me yet...
In most cases mentioned above that should be enaught to work.
nsanow at gmail dot com
I'm at a loss.
I changed permission in /var/spool/lastfm to 777 because none of the songs' info files appeared there otherwise. The current ownership of /var/spool/lastfm is lastfm:root. Shouldn't it be root:lastfm or lastfm:lastfm ?
I'm certain that my /etc/lastfmsubmitd.conf file is edited correctly.
Works perfectly now!
Fancycakes, would you tell step by step what you did?
→ wait = length/2
→ time.sleep(wait)
→ if still_playing(options.artist, options.album, options.title):
→ → submit_to_lastfm(options.artist, options.album, options.title, options.length)
→ → exit(0)
→ exit(1)
where → marks the indentation. The only benifit of the original, as I see it, is that it will make the script exit sooner if you change song before waiting the wait number of seconds. In this you will only have to make on comparison during the song, and not 2·length/5 (two ifs, but only every fifth second) which is 72 for 3 minute.
The problem with this change would be if you step through alot of songs you will have alot of sleeping scripts. But hopefully time.sleep is well made, and does not hurt too much.
BTW, my blog software copes with indentation without hacks:
class Foo:
def bar(self):
pass
And if you turn on Restructured text you can use a proper 'code-block'
if length < 15:
submit_to_lastfm(options.artist, options.album, options.title, options.length)
exit(0)
now = int(Popen(["mocp", "-Q", "%cs"], stdout=PIPE).communicate()[0].split("\n")[0])
wait = length/4
c_wait = 0
limit = 600 # 600 seconds == 10 minutes
while now < wait:
c_wait += (wait-now)
time.sleep(wait-now)
# Check if it is still playing every limit seconds
if c_wait > limit:
if not still_playing(options.artist, options.album, options.title):
exit(1)
c_wait -= limit
now = int(Popen(["mocp", "-Q", "%cs"], stdout=PIPE).communicate()[0].split("\n")[0])
if still_playing(options.artist, options.album, options.title):
submit_to_lastfm(options.artist, options.album, options.title, options.length)
exit(0)
exit(1)
If i make one i get error in line 17.
lastfmsubmitd: no account info found; exiting
WTF?! (I've made /etc/lastfmsubmitd.conf edition of course)
I'm afraid I can't offer any more support for this script, or use of lastfmsubmitd, so I'm closing comments on this blog post. If you have solutions rather than questions feel free to e-mail me.