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.

links

social