Play LastFM customized radio streams in iTunes

May 11, '06 07:30:00AM

Contributed by: lbya

last.fm is a website that will analyze the music you like to play, and then find musical recommendations for you. It can also stream you a custom radio station comprising that recommended music (streamed from last.fm's own library). I find it to be a great way to hear new music without really looking for it.

Normally you need to play your recommended radio station in last.fm's proprietary player, but this hint describes how to listen using iTunes. This lets you listen through Airport Express speakers, or is good if you just prefer to do all your listening in iTunes.

  1. Create an account at last.fm.
  2. Download and install the Audioscrobbler plugin for iTunes (it's called iScrobbler) from last.fm. You'll need to enter your last.fm username and password into the preferences. This runs in the background and tells last.fm about your listening habits as you use your iTunes normally (when you play your own music). An invasion of privacy, yes, but that is what you're trying to accomplish -- this not only improves the quality of last.fm's collective musical brain, but is also the thing that allows last.fm to make recommendations for you.
  3. You need to use iTunes for some time (I think at least a week) before last.fm can begin to make recommendations for you. You can see your recommendations on your last.fm recommendations page.
Now here's the hint on how to listen to your recommended radio station through iTunes, instead of using the proprietary player. Download Vidar Madsen's LastFMProxy. This is a Python script that translates (proxies) the station in real time into a standard M3U stream, which iTunes is compatible with. Normally you need to start LastFMProxy from the command line, and then listen in conjunction with a web browser. However, the following steps show you how to start it from the Scripts menu of iTunes.

To run LastFMProxy from iTunes' Scripts menu, do the following:

  1. Unzip LastFMProxy and copy the folder into ~/Library/iTunes/Scripts. Rename the folder lastfmproxy.
  2. In that folder, edit the file config.py to change the username and password settings to be your last.fm username and password.
  3. Download these scripts (4KB; macosxhints mirror) and put them in ~/Library -> iTunes -> Scripts. Restart iTunes so they show up in the Scripts menu. These are simple scripts that just save you from using the command line to control LastFMProxy and integrate it better into iTunes.
The Lastfm Start script is the one that starts the Python proxy, and then tells iTunes to play the stream. It takes a second or two to start playing. If you run this script more than once without quitting the proxy, it's ok -- it shouldn't start two instances of the proxy (because the socket is already in use), but should just tune iTunes into the existing proxy.

For more detail about what's playing, run the Lastfm Control script. This just points Safari to a page generated by the LastFMProxy, which also lets you use Lastfm's Skip and Ban functions, as well as modify the station.

The Lastfm Quit script tells the LastFMProxy server to quit (potentially freeing up some tiny amount of computer resources, compared to just pressing Stop or changing the track in iTunes).

You can also add LastFMProxy's stream to your iTunes library, the URL is http://localhost:1881/lastfm.m3u. This can be convenient so you can switch among playing Lastfm and other things, but remember the proxy needs to be started via the Lastfm Start script before that stream will work.

Other Applescripts could easily be written to control LastFMProxy in other ways, such as to tune into various keyword or neighbor stations, or to do the Skip or Ban functions. See LastFMProxy's Readme file for suggestions. Enjoy your music!

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060507110841475