AudioScrobbler / last.fm support

requests for enhancements, and features for next version

Moderators: Developers, Webadmins

Re: last.fm support

Postby oranges on Thu Feb 21, 2008 7:56 am

cool...thanks I'll check it out.
oranges
n00b
n00b
 
Posts: 2
Joined: Tue Feb 19, 2008 8:21 pm

Re: Solution for Linux users

Postby FrankZabbath on Sun Feb 24, 2008 10:06 am

First of all thanks a lot to magnate and all the other contributors to this audioscrobbler solution. It seems to work very fine now on my NSLU2 (armeb) running unslung 6.10 with firefly svn-1586 and lastfmsubmitd-0.37 with python 2.4. So here's my feedback on my working database query script.

It took me some time until I finally tried out another approach than the one suggested here:

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


So what I basically do is first writing the query result file somewhere outside the spool dir and then move it into the spool. That way lastfmsubmitd processes the file everytime (so far ;).
Additionally I made the script only query the database, if the database file has been changed since the last run. Furthermore a spool file is only written if a database query has been done, instead of always creating 0 byte files when the script runs.
I also had to fix the timezone offset by -1 h ($6-3600 seconds in the gawk statement) in the query result to report GMT+0 timestamps, as otherwise the times would be GMT+1 and thus shown in the future in my last.fm stats.

So here's my currently running script:
Code: Select all
#!/bin/bash

# fetch newly played songs from fireflydb and write
# into lastfmsubmitd readable format

# config
SQLITE=sqlite
DATABASE=/opt/var/mt-daapd/songs.db
LASTFILE=/opt/var/mt-daapd/lastfmsubmit.date
DBLSFILE=/opt/var/mt-daapd/lastfmsubmit.ls

# get last run time
if [ -e $LASTFILE ]
then
  . $LASTFILE
else
  LASTRUN=0
fi

# get last database file date
if [ -e $DBLSFILE ]
then       
  . $DBLSFILE
else     
  DBLSRUN=
fi

# exit when database file unchanged
DBLSNOW=`ls -l $DATABASE`
if [ "$DBLSRUN" == "$DBLSNOW" ]
then
  exit
fi

# log file date
echo "DBLSRUN="$DBLSNOW"" > $DBLSFILE

# query database
OUTFILE=$(mktemp /tmp/mt-daapd-XXXXXXXX)
$SQLITE $DATABASE 'SELECT artist,album,title,track,song_length,time_played FROM songs where time_played > '$LASTRUN' ORDER BY time_played ASC;' | gawk -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-3600) }' > $OUTFILE
mv $OUTFILE /var/spool/lastfm

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

# make lastfmsubmitd files readable
chmod 664 /var/spool/lastfm/*


Be sure to set the paths, the sqlite executable and time offset to your needs. This script needs bash and gawk available via ipkg.
I haven't tried yet to change the shebang line from bash to sh. Might be better to do so.
FrankZabbath
lunatic
lunatic
 

Re: new perl Script

Postby uncleremus on Tue Mar 04, 2008 11:20 am

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


Works fine for me also, very nice job, thanks!

One detail, even if I just scroll past a song, listen for a second. It will scrobble it on last.fm, is there a possibility that it could behave like amarok, iTunes, etc. who has some minor qualifications for a "listen". Like a requirement that half the song should at least have been played, or similar?

(Another thing: The usage message indicates that "-d" is the option for specifying db_file, but in the perl code it looks like it is expecting this as the "-r" option.)
uncleremus
regular
regular
 
Posts: 32
Joined: Sat Jan 27, 2007 2:01 am

Postby magnate on Sat Mar 08, 2008 1:28 pm

Thanks to FrankZabbath for a greatly improved lastfmsubmitd script. It took me hours to figure out why it wasn't working - I kept getting the error message

: no such file or directory

... turned out I had copied the script over in DOS text format, so it was interpreting the first line as

#!/bin/bash ^M

and was looking for a file called ^M.

Ho hum. Sorted now, and running happily.

Thanks again,

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

Postby thorstenhirsch on Sun Sep 21, 2008 1:34 pm

After upgrading Python 2.3 to 2.5.2 on my Linkstation, I'm also able to use lastfmsubmitd with FrankZabbath's script.

If anyone else has problems with 0 byte files in the spool directory, this might be caused by the following line:
Code: Select all
SQLITE=sqlite

Well, in my case it's sqlite3, but that's not the point. The cause was, that sqlite(3) is not given in an absolute path here, so there is no output on STDOUT later in the script when sqlite(3) is being called. To fix the problem, just give the full sqlite(3) path:
Code: Select all
SQLITE=/usr/local/bin/sqlite3

You won't have the problem when $PATH is defined correctly during creation of the bash process, but that's not the case on my Linkstation.
thorstenhirsch
regular
regular
 
Posts: 32
Joined: Fri Jan 05, 2007 5:15 pm

Last.fm scrobbling support on java FireflyClient

Postby caribou on Fri Oct 24, 2008 5:04 am

Hi,

I've just released the version 0.7b of FireflyClient which includes a last.fm scrobbling support :
https://sourceforge.net/project/showfil ... _id=212642

More information available on a thread on this forum about firefly client : http://forums.fireflymediaserver.org/vi ... 8&start=90

I know this is a client-side only solution (compared to a firefly media server plugin) but it may do the trick !

-- caribou
NSLU2 debian slug [etch], Firefly 1586 | Windows XP SP2, Firefly 1586
http://sourceforge.net/projects/fireflyclient/
User avatar
caribou
regular
regular
 
Posts: 57
Joined: Thu Dec 13, 2007 1:08 am
Location: France

Re: AudioScrobbler / last.fm support

Postby pcace on Wed Apr 14, 2010 6:16 am

Hey,

i just tried to install lastfm support in my mt-daapd server. BUT i get a strange error: i changed the path names according to my needs but it simply dont works. what i get is:
Code: Select all
[: 33: -rw-r--r-- 1 mt-daapd nogroup 19552256 2010-04-14 14:48 /var/cache/mt-daapd/songs3.db: unexpected operator

I tried the script from here: http://www.themaelstrom.co.uk/node/10
I run ubuntu 9.04 Server (mt-daapd version svn-1696, sqlite3 version 3.6.16)

Hopefully someone can help me!


Thanks!

Thats the complete output:
user@mashine:~/scripts$ cat lastfmsubmit.sh
#!/bin/bash

# fetch newly played songs from fireflydb and write
# into lastfmsubmitd readable format

# config
SQLITE=/usr/bin/sqlite3
DATABASE=/var/cache/mt-daapd/songs3.db
LASTFILE=./lastfmsubmit.date
DBLSFILE=./lastfmsubmit.ls

# get last run time
if [ -e $LASTFILE ]
then
. $LASTFILE
else
LASTRUN=0
fi

# get last database file date
if [ -e $DBLSFILE ]
then
. $DBLSFILE
else
DBLSRUN=
fi

# exit when database file unchanged
DBLSNOW=`ls -l $DATABASE`
if [ "$DBLSRUN" == "$DBLSNOW" ]
then
exit
fi

# log file date
echo "DBLSRUN=\"$DBLSNOW\"" > $DBLSFILE

# query database
OUTFILE=$(mktemp /tmp/mt-daapd-XXXXXXXX)
$SQLITE $DATABASE 'SELECT artist,album,title,track,song_length,time_played FROM songs where time_played > '$LASTRUN' ORDER BY time_played ASC;' | gawk -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

# Move the file to the daemon spool directory if it is not empty
if [ -s $OUTFILE ]
then
mv $OUTFILE /var/spool/lastfm
fi

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

# make lastfmsubmitd files readable
chmod 664 /var/spool/lastfm/*

user@mashine:~/scripts$ sudo sh lastfmsubmit.sh
[: 33: -rw-r--r-- 1 mt-daapd nogroup 19552256 2010-04-14 14:52 /var/cache/mt-daapd/songs3.db: unexpected operator
user@mashine:~/scripts$
pcace
n00b
n00b
 
Posts: 4
Joined: Wed Dec 02, 2009 5:07 pm

Re: AudioScrobbler / last.fm support

Postby pcace on Wed Apr 14, 2010 6:17 am

Hey,

i just tried to install lastfm support in my mt-daapd server. BUT i get a strange error: i changed the path names according to my needs but it simply dont works. what i get is:
Code: Select all
[: 33: -rw-r--r-- 1 mt-daapd nogroup 19552256 2010-04-14 14:48 /var/cache/mt-daapd/songs3.db: unexpected operator

I tried the script from here: http://www.themaelstrom.co.uk/node/10
I run ubuntu 9.04 Server (mt-daapd version svn-1696, sqlite3 version 3.6.16)

Hopefully someone can help me!


Thanks!

Thats the complete output:
user@mashine:~/scripts$ cat lastfmsubmit.sh
#!/bin/bash

# fetch newly played songs from fireflydb and write
# into lastfmsubmitd readable format

# config
SQLITE=/usr/bin/sqlite3
DATABASE=/var/cache/mt-daapd/songs3.db
LASTFILE=./lastfmsubmit.date
DBLSFILE=./lastfmsubmit.ls

# get last run time
if [ -e $LASTFILE ]
then
. $LASTFILE
else
LASTRUN=0
fi

# get last database file date
if [ -e $DBLSFILE ]
then
. $DBLSFILE
else
DBLSRUN=
fi

# exit when database file unchanged
DBLSNOW=`ls -l $DATABASE`
if [ "$DBLSRUN" == "$DBLSNOW" ]
then
exit
fi

# log file date
echo "DBLSRUN=\"$DBLSNOW\"" > $DBLSFILE

# query database
OUTFILE=$(mktemp /tmp/mt-daapd-XXXXXXXX)
$SQLITE $DATABASE 'SELECT artist,album,title,track,song_length,time_played FROM songs where time_played > '$LASTRUN' ORDER BY time_played ASC;' | gawk -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

# Move the file to the daemon spool directory if it is not empty
if [ -s $OUTFILE ]
then
mv $OUTFILE /var/spool/lastfm
fi

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

# make lastfmsubmitd files readable
chmod 664 /var/spool/lastfm/*

user@mashine:~/scripts$ sudo sh lastfmsubmit.sh
[: 33: -rw-r--r-- 1 mt-daapd nogroup 19552256 2010-04-14 14:52 /var/cache/mt-daapd/songs3.db: unexpected operator
user@mashine:~/scripts$
pcace
n00b
n00b
 
Posts: 4
Joined: Wed Dec 02, 2009 5:07 pm

Re: Solution for Linux users

Postby pcace on Mon May 03, 2010 6:28 am

FrankZabbath wrote:So here's my currently running script:
Code: Select all
#!/bin/bash

# fetch newly played songs from fireflydb and write
# into lastfmsubmitd readable format

# config
SQLITE=sqlite
DATABASE=/opt/var/mt-daapd/songs.db
LASTFILE=/opt/var/mt-daapd/lastfmsubmit.date
DBLSFILE=/opt/var/mt-daapd/lastfmsubmit.ls

# get last run time
if [ -e $LASTFILE ]
then
  . $LASTFILE
else
  LASTRUN=0
fi

# get last database file date
if [ -e $DBLSFILE ]
then       
  . $DBLSFILE
else     
  DBLSRUN=
fi

# exit when database file unchanged
DBLSNOW=`ls -l $DATABASE`
if [ "$DBLSRUN" == "$DBLSNOW" ]
then
  exit
fi

# log file date
echo "DBLSRUN="$DBLSNOW"" > $DBLSFILE

# query database
OUTFILE=$(mktemp /tmp/mt-daapd-XXXXXXXX)
$SQLITE $DATABASE 'SELECT artist,album,title,track,song_length,time_played FROM songs where time_played > '$LASTRUN' ORDER BY time_played ASC;' | gawk -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-3600) }' > $OUTFILE
mv $OUTFILE /var/spool/lastfm

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

# make lastfmsubmitd files readable
chmod 664 /var/spool/lastfm/*


Be sure to set the paths, the sqlite executable and time offset to your needs. This script needs bash and gawk available via ipkg.
I haven't tried yet to change the shebang line from bash to sh. Might be better to do so.



Hey Thank you a lot! it Works good!
What do i have to do to change the "time played" in last fm? Every Song is shown as played 2 hours later than it originaly is!

Any idea what i can do there?


Thanks!

Pcace
pcace
n00b
n00b
 
Posts: 4
Joined: Wed Dec 02, 2009 5:07 pm

Previous

Return to Feature Requests

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest