Dec 28, 2008

HOWTO: adding Last.fm scrobbling to mediatomb

Lastfmlib is C / C++ library allowing music applications to "scrobble" tracks on last.fm.

A patch has been recently released to integrate this library with mediatomb, so let's get to work :)

FYI, this is written using Ubuntu 8.04 and mediatomb 0.12 (SVN build 1997). I also assume you have a mediatomb source tree ready (if not, here's how).

1) Installing lastfmlib

First of all, we need to fetch the log4cpp library, which is used by lastfmlib to log its actions (very useful for troubleshooting!).

ubuntu% sudo apt-get install liblog4cpp5-dev

Now, let's fetch the lastfmlib source (0.1.3 at the time of this writing) as well as the mediatomb patch:

ubuntu% wget http://lastfmlib.googlecode.com/files/lastfmlib-0.1.3.tar.gz
ubuntu% wget http://lastfmlib.googlecode.com/svn/trunk/mediatomb.patch

Building the library is very straightforward:

ubuntu% tar xvfz lastfmlib-0.1.3.tar.gz
ubuntu% cd lastfmlib-0.1.3
ubuntu% ./configure --prefix=/usr/local --enable-logging
ubuntu% make
ubuntu% sudo make install
ubuntu% sudo ldconfig

Done! Let's patch mediatomb now.

2) Patching & building mediatomb

In the mediatomb source directory, let's apply the patch:

ubuntu% patch -p0 < ../lastfmlib-0.1.3/mediatomb.patch All hunks should be successful. Now, run configure to take lastfmlib into account:

ubuntu% ./configure --prefix=/usr/local
output removed
checking lastfmlib/lastfmscrobbler.h usability... yes
checking lastfmlib/lastfmscrobbler.h presence... yes
checking for lastfmlib/lastfmscrobbler.h... yes
output removed
CONFIGURATION SUMMARY ----
output removed
lastfm : yes
output removed

OK, the library has been properly detected. Now, let's (re)build mediatomb:

ubuntu% make clean
ubuntu% make
ubuntu% sudo make install

3) Configuring mediatomb

In the mediatomb config file (~/.mediatomb/config.xml), we need to add this to the top-level section:
<lastfm enabled="yes">
<username>Your_LastFM_username</username>
<password>Your_LastFM_password</password>
</lastfm>
That's it :)

4) Testing!

Now, let's start mediatomb, fire up the PS3 (or whatever device you're streaming to) and play some mp3 tracks.

In the lastfmlib log, you should see something similar to this:

ubuntu% tail -f /tmp/lastfmliblog.txt
1230460109 INFO : Authentication successfull for user: Your_LastFM_username
1230460109 INFO : Authenticate thread finished
1230462337 INFO : startedPlaying Tanker Mot Tind (Gryning)
1230462517 INFO : startedPlaying Ved Steingard
1230462517 INFO : sendInfo thread started
1230462517 INFO : Track "Tanker Mot Tind (Gryning)" can be committed: conditions OK
1230462517 INFO : Buffered tracks submitted
1230462517 INFO : sendInfo thread finished

And now the mediatomb console output:

2008-12-28 12:05:37 INFO: Artist: Borknagar
2008-12-28 12:05:37 INFO: Title: Tanker Mot Tind (Gryning)
2008-12-28 12:08:37 INFO: Artist: Borknagar
2008-12-28 12:08:37 INFO: Title: Ved Steingard

Of course, you can also log in on your last.fm account and see the tracks listed there. Pretty cool :)

One (very minor) gripe: scrobbling doesn't seem to work for file formats which are not natively handled by the PS3, notably FLAC. Maybe metadata extraction works differently for these files, as they need to be transcoded on the fly? Or have I missed something ? Anyway, I contacted the author about this, I'll post more details when I get them.

[Updated on 2009/01/02] Says Dirk Vanden Boer, the author of the library: "I haven't tried playing files that need be transcoded yet, I'll take a look and see if a different code path is taken in case of transcoding". I'll keep you posted.

That's it for today :)

5 comments:

  1. Hi Julien
    Thanks for the HowTo, I've done it here :-)
    btw nice blog.

    Kind regards
    rain

    backlink: MediaTomb und last.fm (sorry, it's in german)

    ReplyDelete
  2. Awesome how-to :)

    Got a little problem though...I'm stuck at the part:

    "2) Patching & building mediatomb

    In the mediatomb source directory, let's apply the patch:"


    Where exactly is the mediatomb source directory, and what's the easiest way to navigate to it?

    Thanks a lot man!

    ReplyDelete
  3. Hi Stephen,

    you need to build mediatomb from source as explained in http://juliensimon.blogspot.com/2008/12/howto-compiling-mediatomb.html

    The mediatomb source directory is the one used for this build, so you just need to navigate to it before you apply the patch :)

    Cheers!

    ReplyDelete
  4. Hi, I'm stucked at part 2. I use the latest svn version (Revision: 2022).
    When I run ./configure
    I get:
    checking lastfmlib/lastfmscrobbler.h usability... yes
    checking lastfmlib/lastfmscrobbler.h presence... yes
    checking for lastfmlib/lastfmscrobbler.h... yes

    which is good, but in Configuration summary I have
    lastfm : Missing

    Running on Centos 5.4
    Thanks,

    ReplyDelete