Home > Fixes > Last.FM submissions with Audacious

Last.FM submissions with Audacious

Some time ago the good folks behind my favorite media player Audacious decided to abandon in-built support for Last.FM submissions.

The reasoning behind this seems to be that the Last.FM API was becoming a little too much to maintain which I suppose is fair enough in its quest to remain just a music player i.e. not a screen-hogging iTunes clone like so many others.

Heres how to put Last.FM support back into Audacity.

I’m going to assume you are a sensible person and using a Debian based system rather than Fedora. If you are one of these hat loving deviants, substitute ‘yum’ for apt-get below and feel free to voyage though the countless pains required to get Yum to actually do its job.

Installing LastFMSubmitD

I’m not sure on the capitalization of the daemon process LastFMSubmitD so that might be the wrong name entirely.

Anyway, first install pretty much the only component we need:

apt-get install lastfmsubmitd

OPTIONAL – Set up the HTTP_PROXY

For some reason the daemon does not get proxy details right. This is easily fixed by opening /etc/init.d/lastfmsubmitd in your favorite editor and inserting the following line somewhere near the top (I put it after the ‘GROUP=’ line which should be the last bit of the daemon config area).
If you have no idea what a proxy is or why you should be doing this you can probably skip this section.

export http_proxy="http://whatever.stupid.proxy.edu.au:8080/"

Parse Audacious output

Dump the following script somewhere you can find it. For this example I will use /home/user/bin/scrobble

?Download scrobble
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
if [ ! -x '/usr/lib/lastfmsubmitd/lastfmsubmit' ]; then
	echo "LastFMSubmitD does not appear to exist on this machine"
	echo "You can install it using Apt or Yum"
	exit 1
fi
if [ "$#" == 0 ]; then
	echo 'Usage: scrobble "<artist> - <song>" "<length>"'
	exit 1
fi
 
ARTIST=${1%% - *}
SONG=${1##* - }
LENGTH=$[ $2 / 1000 ]
echo "ARTIST = [$ARTIST]"
echo "SONG = [$SONG]"
echo "LENGTH = [$LENGTH]"
 
/usr/lib/lastfmsubmitd/lastfmsubmit --artist "$ARTIST" --title "$SONG" --length "$LENGTH"

Pointing Song Change at your script

First make sure you have the Song Change plugin enabled in Audacious first.

Now point the command Audacious is to run when starting a new song at the script in the following way:

/home/user/bin/scrobble "%s" "%l"

All done. Now any tracks played via Audacious will be passed to the script which will parse the incoming song title into a format that the LastFMSubmitD daemon can use.

Categories: Fixes Tags: , ,
  1. June 14th, 2010 at 22:22 | #1

    Hey! After writing my own script i searched internet for similar and i found yours. Mine has some features like scrobble after 10 seconds and checking if it’s running again. You can check it here :
    http://smali.me/2gb
    Ned

    • June 15th, 2010 at 08:35 | #2

      Its great that you have improved the functionality even more.

      Would it be possible to get a link back to the original entry though if anyone wants the original?

  2. April 5th, 2011 at 14:42 | #3

    Thanks for this.
    i made a couple of changes for it to work for me:

    first of all, the download came dos-formatted, so i had to run dos2unix on it.

    then, because i have customised my audacious playlist settings i had to change the lines which split artist and song. my playlist looks like:
    ${track-number}:${title} ${?album: – ${album}}${?artist: – ${artist}} ${?year: [${year}]}
    which produces titles like
    1:Everyday – And Then Nothing Turned Itself Inside Out – Yo La Tengo [2000]

    and finally, i’m not running lastfmsubmit as daemon, so i just call it for each submission

    so here is my scrobble script:

    #!/bin/bash

    if [ ! -x '/usr/lib/lastfmsubmitd/lastfmsubmitd' ]; then
    echo "LastFMSubmitD does not appear to exist on this machine"
    echo "You can install it using Apt or Yum"
    exit 1
    fi
    if [ "$#" == 0 ]; then
    echo 'Usage: scrobble " - " ""'
    exit 1
    fi

    #ARTIST=${1%% - *}
    #SONG=${1##* - }
    # andrew has audacious set to print {track}:{Song} - {album} - {artist} [{year}] all this would be better done with sed, but i like trying it in bash
    # split $1 and remember everything after the colon
    artistsongyear=${1##*:}
    # split that and remember everything before the bracked (no good for songs with brackets!)
    songalbumartist=${artistsongyear%% [*}
    # split that on the dashes which separates song - album - artist
    ARTIST=${songalbumartist##* - }
    SONG=${songalbumartist%% - *}
    songalbum=${songalbumartist#* - }
    ALBUM=${songalbum%% - *}
    # length is in milliseconds
    LENGTH=$[ $2 / 1000 ]
    echo "ARTIST = [$ARTIST]"
    echo "ALBUM = [$ALBUM]"
    echo "SONG = [$SONG]"
    echo "LENGTH = [$LENGTH]"

    #this will log the song details to /var/spool/lastfm
    /usr/lib/lastfmsubmitd/lastfmsubmit --artist "$ARTIST" --title "$SONG" --length "$LENGTH"
    # it's made to be run as a daemon, but just as easy to run once
    /usr/lib/lastfmsubmitd/lastfmsubmitd

  3. April 5th, 2011 at 14:44 | #4

    (the commenting system was surprisingly kind to this script – the only thing missing is the usage line – but you’ll have to turn all the inverted commas back to ones that bash understands)

    • April 5th, 2011 at 14:52 | #5

      Fixed up the previous comment by enclosing the code in <code> tags. WordPress seems to understand that anything within them is not to be trifled with.

  1. No trackbacks yet.
*