Playing Last.fm from emacs

I enjoy listening to Last.fm and recently decided it would be handier to control it from within my emacs session. Getting it to work didn't take too long but wasn't as straightforward as I hoped, mostly because it's easier to find documentation for older versions of emms (including on the official website) and the last.fm parts have been entirely rewritten recently. Anyhow! If you're in a rush, the short version is: find the latest version of the code and follow the documentation from the source itself!

What to install

From your package manager, using Debian here:

aptitude install emms mplayer2

Note, that installing mplayer instead worked fine on an Ubuntu machine.

Getting an API key

Search the documentation linked above to get more details. Basically, using the latest version of the Last.fm API requires a secret API key, which isn't a concept that works well with GPL software. To work around this, we request a personal API key, which we will add to our .emacs config file.

Request a key at Last.fm. The keys will be displayed on screen rather than sent to you, therefore write them down now. As far as I can tell the "app description" will only be seen by yourself, when you allow emms-lastfm-client to access your Last.fm account so don't worry too much about the description.

.emacs

Add the following to your config file:

(require 'emms-setup)
(emms-all)
(emms-default-players)
(setq emms-lastfm-client-username "myusername")
(setq emms-lastfm-client-api-key "myapikey")
(setq emms-lastfm-client-api-secret-key "mysecretkey")

Setting up emms-lastfm-client

Now, within emacs (taken straight from the docs!):

  1. M-x emms-lastfm-client-user-authorization - this will open a web page, asking if you want to grant access to the app (with the name and description you gave it when requesting the API key)
  2. M-x emms-lastfm-client-get-session - this is to store the authorisation key so you don't have to go through the authorisation process every time. If it doesn't work you might need to first create ~/.emacs.d/emms manually.

You're set! M-x emms-lastfm-client-play-similar-artists to select who to listen to :)

Useful tips

To stop the music: M-x emms-stop.

To remove the url display/track information:  M-x emms-mode-line-toggle (or -disable) and to remove the playing time information: M-x emms-playing-time-disable-display (they push the org messages too far out right!)

Other error messages

Some messages you may encounter along the way...

Contacting host: ws.audioscrobbler.com:80
progn: missing variables to generate handshake call

The documentation seems to suggest that setting a username is optional, but it's not. Make sure your .emacs contains your username in addition to the API key and secret key.

f: Don't know how to play track: (*track* (type . url) (name . "http://play.last.fm/user/1234567890abcdef0.mp3") (metadata))

emms uses an external program to play music, which is why you need to install mplayer or vlc.


< Back to main >

Well done Julie. This is a real hackers hack. I guess some people might wonder why you choose emacs as your favourite music player - but just ignore them :-) #1. Posted by OpenID Brian O'Donovan (Website) on Wed 09 Nov 2011, 9:07

Well... This was really a simple struggle to get the plug-in - that's where the real hacker's hack's at! - to work, so I don't think I deserve too much credit :-)

I don't know if I would qualify emacs as my favourite music player but on days where I spend all my time in the editor, it's a lot handier to have the music control be a M-x command away :D
#2. Posted by jpichon (Website) on Thu 10 Nov 2011, 8:37

Glad to see you're getting the Emacs way of thinking! #3. Posted by John (Website) on Sat 12 Nov 2011, 19:01

Hello! This text is normally hidden with CSS. If you can see this, you'll also see two additional fields with no label on the form. Leave them as is, as those are aimed at catching form-filling spam bots. Thank you!

    Name: (or OpenID Sign in with OpenID)
      Email: (Not published)
        Website:
          Comment:
           

          < Back to main | Up >