Reply To: AudioScrobbler / last.fm support

#5244
magnate
Participant

@magnate wrote:

Hi Ron,

Are you familiar with lastfmsubmitd? Here:

http://www.red-bean.com/~decklin/software/lastfmsubmitd/

It takes the pain out of writing lastfm plugins, because all you need to do is have the server output details of each song served to /var/spool/lastfm/

Well, I finally managed to adapt the script posted by riro earlier in this thread, for use with lastfmsubmitd. Here it is, in case anyone else wants to use it:

#!/bin/bash
SQLITE="sqlite3"
DATABASE="/var/cache/mt-daapd/songs3.db"
LASTFILE=/var/cache/mt-daapd/lastfmsubmit.date
OUTFILE=$(mktemp /var/spool/lastfm/mt-daapd-XXXXXXXX)

if [ -e $LASTFILE ]
then
. $LASTFILE
else
LASTRUN=0
fi

$SQLITE $DATABASE 'SELECT artist,album,title,track,song_length,time_played FROM songs where time_played > '$LASTRUN' ORDER BY time_played ASC;' | awk -F '|' '{ printf "---nartist: "%s"nalbum: "%s"ntitle: "%s"ntrack: %snlength: %dntime: !timestamp %sn",$1,$2,$3,$4,$5/1000,strftime("%Y-%m-%d %T",$6) }' > $OUTFILE

echo "LASTRUN="`date +%s` > $LASTFILE

chmod 775 /var/spool/lastfm/*

Run this script as a cron job and it automatically scrobbles your plays to lastFM. I run it daily, because I only listen for a couple of hours a day, but you can run it hourly or even more frequently if you want. It has a few limitations:

1. It won’t scrobble partially-played tracks (this is also the behaviour of the default LastFM client, so fair enough)
2. It won’t scrobble tracks which are paused and then restarted (because they count as partially played and are not recorded in songs3.db)
3. It will only scrobble a given track once each time it is invoked (because songs3.db records only the last play of any track)

N.B. If lastfmsubmitd is not packaged for your system, don’t forget to install Python along with it. Also note that lastfmsubmitd terminates itself on any error, so check /var/log/lastfm if you have any scrobbling probs.

Obviously it’s not as good as having mt-daapd output the details of each song into /var/spool/lastfm play by play, but it’s a reasonable stopgap. I don’t tend to listen to any song more than once in a day, so it works for me.

Cheers,

CC