AudioScrobbler / last.fm support

requests for enhancements, and features for next version

Moderators: Developers, Webadmins

Solution for Linux users

Postby magnate on Sat Feb 02, 2008 2:20 am

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:

Code: Select all
#!/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: %s\nlength: %d\ntime: !timestamp %s\n",$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
"When I gave food to the poor, they called me a saint. When I asked why the poor were hungry, they called me a communist."
magnate
user
user
 
Posts: 26
Joined: Tue Oct 16, 2007 7:25 am
Location: London, UK

Re: new perl Script

Postby OxonHammer on Mon Feb 04, 2008 1:31 am

t0m wrote:I've modified the rockscrobbler perl script by noleti so you actually only need one script.

this script supports compilations. You can download it from:

http://rapidshare.com/files/31760952/firescrobbler.zip

this is a sqlite3 version - for sqlite2 add use DBD::SQLite2;

I've been testing this script for two weeks now (cronjob running every 5 minutes) - its working fine for me.
/t0m


Hello,

I have tried unsuccessfully to use the above script, as I keep getting a "Can't locate DBD/SQLite2" message. I can confirm through my ipkg list_installed command thast I am running both sqlite and sqlite2 packages.

I have also tried to run perl -MCPAN -e 'install DBD::SQLite2' but it doesn't recognise it!

I have installed:
ipkg install perl
ipkg install perl-wwwlib

I hope someone can help me with this, as I've tried everything I can think of, or seeminly find on Google searches.

For info, I'm a complete Newbie at this sort of thing, so real basic instructions would be very welcome.

I'm running last Friday's nighly release on an unslung NSLU2.

Many thanks if you can help, as this would complete my set-up.
OxonHammer
n00b
n00b
 
Posts: 6
Joined: Mon Feb 04, 2008 1:26 am

Re: new perl Script

Postby rpedde on Mon Feb 04, 2008 11:13 pm

OxonHammer wrote:
t0m wrote:I've modified the rockscrobbler perl script by noleti so you actually only need one script.

this script supports compilations. You can download it from:

http://rapidshare.com/files/31760952/firescrobbler.zip

this is a sqlite3 version - for sqlite2 add use DBD::SQLite2;

I've been testing this script for two weeks now (cronjob running every 5 minutes) - its working fine for me.
/t0m


Hello,

I have tried unsuccessfully to use the above script, as I keep getting a "Can't locate DBD/SQLite2" message. I can confirm through my ipkg list_installed command thast I am running both sqlite and sqlite2 packages.

I have also tried to run perl -MCPAN -e 'install DBD::SQLite2' but it doesn't recognise it!

I have installed:
ipkg install perl
ipkg install perl-wwwlib

I hope someone can help me with this, as I've tried everything I can think of, or seeminly find on Google searches.

For info, I'm a complete Newbie at this sort of thing, so real basic instructions would be very welcome.

I'm running last Friday's nighly release on an unslung NSLU2.

Many thanks if you can help, as this would complete my set-up.


You are using sqlite3, so use the sqlite3 instructions.

-- Ron
User avatar
rpedde
Site Admin
Site Admin
 
Posts: 4251
Joined: Mon Nov 22, 2004 12:55 am

Postby OxonHammer on Tue Feb 05, 2008 1:05 am

I am running what I thought was the latest stable nighly release, and this appears to have created a songs.db file in /opt/etc/mt-daapd/, and this is a sqlite2 file.

Where is the nightly version that runs sqlite3?

Thanks.
OxonHammer
n00b
n00b
 
Posts: 6
Joined: Mon Feb 04, 2008 1:26 am

Postby rpedde on Thu Feb 07, 2008 1:25 am

OxonHammer wrote:I am running what I thought was the latest stable nighly release, and this appears to have created a songs.db file in /opt/etc/mt-daapd/, and this is a sqlite2 file.

Where is the nightly version that runs sqlite3?

Thanks.


Grumble.

As was pointed out to me in another forum, I've somehow messed up my builds and and building versions that *don't* support sqlite3. I'll try and rectify this in upcoming nightlies.

Sorry! I thought I had switched defaults on the packages all to sqlite3. Maybe I just dreamed it. :)

-- Ron
User avatar
rpedde
Site Admin
Site Admin
 
Posts: 4251
Joined: Mon Nov 22, 2004 12:55 am

Postby OxonHammer on Thu Feb 07, 2008 1:38 am

It could have been me though. I followed the instructions inside http://wiki.fireflymediaserver.org/NSLU2_Installation which pointed me towards the http://ipkg.fireflymediaserver.org/armeb release?

I've found instructions for editing the .conf file, and also some others to drop the songs.db file and replace with the songs3.db file, so I sould be OK now.

For info, if someone else wants this stuff, the instructions I found are:

sqlite /path/to/songs.db .dump | sqlite3 /path/to/songs3.db (upgrading to sqlite3 database)
OxonHammer
n00b
n00b
 
Posts: 6
Joined: Mon Feb 04, 2008 1:26 am

Postby OxonHammer on Thu Feb 07, 2008 11:25 am

Well, getting somewhere, but now I'm seeing errors within the perl script, that don't help me identify where my process is failing.

I'm getting the following message, which hopefully someone will be able to identify what my problem is?

OUCH! Could not complete the handshake: 500 server closed connection without sending any data back.

Now I presume this must have something to do with the code inside the Audio::Scrobbler.handshake() method? But can't tell if the problem is on my end or theirs?

Hope you can help? I feel like I'm getting within touching distance, and don't want to quit on this.
OxonHammer
n00b
n00b
 
Posts: 6
Joined: Mon Feb 04, 2008 1:26 am

Postby OxonHammer on Mon Feb 11, 2008 2:52 am

Discovered the bad handshake is a last.fm problem. I get it about 25% of the time!

But I now have this running, and seemingly sending data to post.audioscrobbler.com, but yet nothing is getting added to my profile. I believe I have tracked this down to bad data coming out of sqlite3. For some reason, when I try to send the length and last_played attribute, these are both 0 values.

This is odd, as I have run the sql statement directly inside sqlite3, and the data is inside the database and is displayed on screen, but yet the line (and I'm doing this from memory, so it might be wrong) $_->[4] returns zero, as does $_->[5]. These are the length and last_played columns.

I have tried adding a column alias to these columns, and I was going to play around with reordering these columns to see if this makes a difference, but can't see why they are both returning zero values, when the data is in the database?

I believe this is why the script is failing for me, as these must be required fields inside the scrobbler?

Thanks.
OxonHammer
n00b
n00b
 
Posts: 6
Joined: Mon Feb 04, 2008 1:26 am

Postby OxonHammer on Mon Feb 11, 2008 2:28 pm

Must have been the DBI:Sqlite driver, as I had to fix this by using the following SQL:

SELECT artist, track, album, cast(song_length as varchar) as song_length FROM songs

as the int/double column was getting turned into a zero, and last.fm wasn't liking this!
OxonHammer
n00b
n00b
 
Posts: 6
Joined: Mon Feb 04, 2008 1:26 am

Re: Solution for Linux users

Postby barefoot on Mon Feb 11, 2008 5:56 pm

magnate wrote: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.


Thanks for the script. However, does it really work for you every time? It does not for me, as from time to time lastfmsubmitdaemon ignores the written files and does not submit the information. What is submitted and what not is fairly random.

I first suspected empty files, but that's not the reason. No clue...
barefoot
user
user
 
Posts: 10
Joined: Wed Aug 29, 2007 3:25 pm

Re: Solution for Linux users

Postby magnate on Wed Feb 13, 2008 2:18 am

barefoot wrote:
magnate wrote: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.

Thanks for the script. However, does it really work for you every time? It does not for me, as from time to time lastfmsubmitdaemon ignores the written files and does not submit the information. What is submitted and what not is fairly random.

I first suspected empty files, but that's not the reason. No clue...

Oh dear, sorry to hear that it's giving you trouble. It took me a long time to get it working right, but as posted it now works for me every time. I've checked, and so far it hasn't failed to scrobble anything I've listened to, since it was finished.

What is in your lastfmsubmitd logs? (/var/log/lastfm/*)
What versions are you running (of mt-daapd, of python, etc.)?
What distro are you using?

I wonder if we are using slightly different versions of lastfmsubmitd - I'm using the one packaged for Debian, which I think has been slightly tweaked from the original.

Sorry I don't have any better ideas at the moment, but happy to try and help.

Cheers,

CC
"When I gave food to the poor, they called me a saint. When I asked why the poor were hungry, they called me a communist."
magnate
user
user
 
Posts: 26
Joined: Tue Oct 16, 2007 7:25 am
Location: London, UK

Re: Solution for Linux users

Postby barefoot on Wed Feb 13, 2008 3:29 am

magnate wrote:What is in your lastfmsubmitd logs? (/var/log/lastfm/*)
What versions are you running (of mt-daapd, of python, etc.)?
What distro are you using?

I wonder if we are using slightly different versions of lastfmsubmitd - I'm using the one packaged for Debian, which I think has been slightly tweaked from the original.

Sorry I don't have any better ideas at the moment, but happy to try and help.


Thanks for the help. Actually, I was successful in working around the problem yesterday, even if I don't know the exact reason for failure. What I now do is: At the end of the script, I sleep for 5 second and then collect all files in the spool directory (if still existent) to one single file in a separate place and copy it back to the spool directory. This file is recognized reliably (and if not, it is collected next time), all the others get erased. I don't know why it works, but it does.

lastfmsubmitd recognizes the files it does not scrobble (if I erase them, it complains that they vanished and crashes). Maybe it works too fast and begins scanning the files before they are completely written - but then my workaroung should also fail. No clue.

I use lastfmsubmitd from sources on a slow MIPS architecture with SLUG binaries. python is actually 2.4, maybe should I upgrade to 2.5?
barefoot
user
user
 
Posts: 10
Joined: Wed Aug 29, 2007 3:25 pm

Re: Solution for Linux users

Postby magnate on Thu Feb 14, 2008 1:00 am

barefoot wrote:
magnate wrote:What is in your lastfmsubmitd logs? (/var/log/lastfm/*)
What versions are you running (of mt-daapd, of python, etc.)?
What distro are you using?

I wonder if we are using slightly different versions of lastfmsubmitd - I'm using the one packaged for Debian, which I think has been slightly tweaked from the original.

Sorry I don't have any better ideas at the moment, but happy to try and help.

Thanks for the help. Actually, I was successful in working around the problem yesterday, even if I don't know the exact reason for failure. What I now do is: At the end of the script, I sleep for 5 second and then collect all files in the spool directory (if still existent) to one single file in a separate place and copy it back to the spool directory. This file is recognized reliably (and if not, it is collected next time), all the others get erased. I don't know why it works, but it does.

lastfmsubmitd recognizes the files it does not scrobble (if I erase them, it complains that they vanished and crashes). Maybe it works too fast and begins scanning the files before they are completely written - but then my workaroung should also fail. No clue.

I use lastfmsubmitd from sources on a slow MIPS architecture with SLUG binaries. python is actually 2.4, maybe should I upgrade to 2.5?

Well, according to Debian, lastfmsubmitd is agnostic about which version of python you have, so it shouldn't be necessary - but it can't do any harm to upgrade. If you wanted to look into lastfmsubmitd itself (it's actually only a couple hundred lines of python code), you could probably find where it's waiting for files to appear in the spool dir, and lengthen the wait from every few seconds to every minute or so - that should solve the slow writing problem, if that's the cause of the failure.

I remembered one other thing yesterday - the awk invocation in the script uses the strftime feature which is in gawk but not in mawk. I thought that might have been the problem, if you were running mawk, but it would have had a completely different solution from the one you found. Oh well. Well done on sorting it out,

CC
"When I gave food to the poor, they called me a saint. When I asked why the poor were hungry, they called me a communist."
magnate
user
user
 
Posts: 26
Joined: Tue Oct 16, 2007 7:25 am
Location: London, UK

last.fm support

Postby oranges on Tue Feb 19, 2008 8:28 pm

I would love to see last.fm support for windows users. I love my soundbridge and I love firefly, but I really, really miss last.fm....
oranges
n00b
n00b
 
Posts: 2
Joined: Tue Feb 19, 2008 8:21 pm

Re: last.fm support

Postby jtbse on Wed Feb 20, 2008 9:53 am

oranges wrote:I would love to see last.fm support for windows users. I love my soundbridge and I love firefly, but I really, really miss last.fm....


oranges...

Have you seen sbPopper?

http://www.monkeylicense.com/sbpopper

Runs in windows and "watches" your Soundbridge for what's playing to Scrobble it. Disadvantage is you have to keep Windows and Last.FM running for it to work, but guessing you keep Win running anyway if you run Firefly on Windows.
jtbse
regular
regular
 
Posts: 51
Joined: Fri Aug 18, 2006 3:09 pm

PreviousNext

Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 0 guests