Listening to Last.fm in Emacs

During the backup process before I had upgraded my notebook to Fedora 10, I decided not to copy back my Music folder to the fresh installation, but start using Last.fm whenever I’d like to listen to music. The question came quite straight—so how to play Last.fm streams in Emacs?

Emacs has its great multimedia system, which has Last.fm support in development stage. Following the instructions on EMMS‘s homepage and rizoma’s dotemacs, soon I got Last.fm working under my Emacs.

(To be exact, I used the EMMS source code patched by tsdh. It has some convenient addons.)

Put the following to into your dotemacs:

(add-to-list 'load-path "~/elisp/emms/")
(require 'emms-setup)
(emms-devel)
(emms-default-players)
(emms-lastfm-enable)

At this point, you’re almost ready to play the radio. You still need to set your Last.fm username and password. For the former, you may simply customize `emms-lastfm-username‘ for future sessions, but for the latter, I don’t recommend you to store your password in a plain text file—you’d rather add the following advise into your dotemacs, that asks you interactively for your Last.fm password every time you start the radio.

(defadvice emms-lastfm-radio (before read-passwd (lastfm-url))
  (if (string= emms-lastfm-password "")
      (setq emms-lastfm-password (read-passwd "Password: "))))

(ad-activate 'emms-lastfm-radio)

Go listening to Last.fm!

M-x emms-lastfm-radio-similar-artists RET angelspit

With the offical code, try this:

M-x emms-lastfm-radio RET lastfm://artist/Imperial brothers/similarartists