FireFly Media Server (formerly mt-daapd) › Firefly Media Server Forums › Firefly Media Server › Feature Requests › AudioScrobbler / last.fm support
- This topic has 53 replies, 18 voices, and was last updated 10 years, 11 months ago by
pcace.
-
AuthorPosts
-
21st February 2008 at 2:56 pm #5259
Anonymous
Inactivecool…thanks I’ll check it out.
24th February 2008 at 5:06 pm #5260FrankZabbath
GuestFirst 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:
#!/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: %snlength: %dntime: !timestamp %sn",$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.4th March 2008 at 6:20 pm #5261uncleremus
Participant@t0m wrote:
I’ve been testing this script for two weeks now (cronjob running every 5 minutes) – its working fine for me.
/t0mWorks 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.)
8th March 2008 at 8:28 pm #5262magnate
ParticipantThanks 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
21st September 2008 at 8:34 pm #5263thorstenhirsch
ParticipantAfter 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:
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:
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.
24th October 2008 at 12:04 pm #5264Anonymous
InactiveHi,
I’ve just released the version 0.7b of FireflyClient which includes a last.fm scrobbling support :
https://sourceforge.net/project/showfiles.php?group_id=212642More information available on a thread on this forum about firefly client : http://forums.fireflymediaserver.org/viewtopic.php?t=7198&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
14th April 2010 at 1:16 pm #5265pcace
ParticipantHey,
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:
[: 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:
[email protected]:~/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: %snlength: %dntime: !timestamp %sn”,$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/*[email protected]:~/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
[email protected]:~/scripts$14th April 2010 at 1:17 pm #5266pcace
ParticipantHey,
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:
[: 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:
[email protected]:~/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: %snlength: %dntime: !timestamp %sn”,$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/*[email protected]:~/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
[email protected]:~/scripts$3rd May 2010 at 1:28 pm #5267pcace
Participant@FrankZabbath wrote:
So here’s my currently running script:
#!/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: %snlength: %dntime: !timestamp %sn",$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
-
AuthorPosts
- The forum ‘Feature Requests’ is closed to new topics and replies.