June 24, 2012

Configure MPD for last.fm streaming

The Music Player Daemon is a powerful way of listening and playing music remotely. Not to mention the daemon itself is lightweight and the server / client compatibility across different operating systems is pretty good.

This tutorial though is not aimed at showing how to configure MPD, but to demonstrate how to add last.fm stream playing compatibility to it, which is available since version 0.15. We will focus on version 0.16 though, which comes with a bit of a different syntax. Please make sure you have installed 0.16 in your distribution of choice and the following three links should help you get started with MPD if you don’t have it running yet:

http://mpd.wikia.com/wiki/Install

http://mpd.wikia.com/wiki/Configuration

http://crunchbanglinux.org/forums/topic/17386/the-ultimate-mpd-guide/ – also useful for mpdscribble configuration

Now that you have MPD up and running (or already had it), what you need to do is add the following configuration snippet at the end of your mpd.conf. Usually this file is found at /etc/mpd.conf but this might differ depending on your distribution.

# Last.fm playback
playlist_plugin {
    name          "lastfm"
    user          "lastfm_username"
    password      "md5sum_of_your_lastfm_password"
}

Be VERY careful when md5sum-ing your last.fm password. The most common mistake is just echo-ing the password into md5sum. That will introduce a new line at the end of your password, totally messing up your md5 and you won’t be able to connect. One way of doing this correctly is to echo with “-n” which will leave the new line out:

echo -n "your_password" | md5sum -

This will give you your correct md5. Paste this into the mpd.conf section mentioned above, restart mpd and you are done!

Now to use this, I am assuming you are using the command line client “mpc” which is also pretty powerful and lightweight. Most graphical mpd clients are not able to search and load last.fm streams. For example, you want to load The Doors and similar artists:

mpc load "lastfm://artist/The Doors"

or you want to load the recommandations stream for your user:

mpc load "lastfm://user/your_user/recommended"

Now, if you are like me and don’t like the syntax above, I have written a bash wrapper script around “mpc” called “mpl” that makes the above a bit easier. You can find it here, along with the readme on how to use it: https://github.com/danakim/mpl

Or just download it directly from: https://github.com/danakim/mpl/zipball/master. It contains the readme and the script does have a help section to show you how to use it.