Play last.fm streams without the player
Or: The last.fm protocol explained a bit.
Last.fm is a web radio service. But: It will happily play what you like, users can enter their favorite bands into a special player software, and then listen to similar music all day long.
So you want to roll your own player software?
Or: You can’t install stuff on your computer, but still want to play their streams?
Read on for help.
I expect that nobody gets upset for me disclosing the protocol. The various player software is freely available, and the protocol can be reverse engineered from that.
This is exactly how this guide was done... (using Ethereal for network analysis)
What you need
Last.fm consists of a shoutcast mp3 stream, and some webservices. To play a stream, you will need at least:
* A shoutcast-stream receiver, like, for example, Winamp (or any media player, basically)
* An at least 128k internet connection
* A means to use the http protocol (like, a browser)
* A means to computer MD5 sums
What to do
1. Login to last.fm, obtain a session
2. Tune to a station
3. Connect to the stream
Logging in:
To get a session, compute the md5sum of your password. An md5sum is the result of a special one-way function which transforms your password into a specific string (looking like garbage, but with a meaning). Different password leads to a different string. The reverse transformation (md5sum to password) is next to impossible, thereby guarding your password during transmission.
If you have access to a Unix-style machine, you can use the md5sum utility. Open a console and type “md5sum” followed by a return. Now enter your last.fm password and then press Ctrl and D at the same time. The odd-looking string directly behind your password is the md5sum.
Others can try to enter their password into the box at Rednoize here to compute their md5sum.
Then call this URL (in a browser, or whereever), replacing everything in <> by the real values (enter this all in one line):
http://ws.audioscrobbler.com/radio/handshake.php?version=1.1.1&platform=linux&username=
&
passwordmd5=&debug=0&partner=
I don’t know yet what the version, debug, platform and partner parameters do, if anything. You’ll get something like this as a result: (plain text)
session=9ac4454642865a57252e2b9f917fc453
stream_url=http://streamer1.last.fm:80/last.mp3?Session=9ac4454642865a57252e2b9f917fc453
subscriber=0
framehack=0
base_url=ws.audioscrobbler.com
base_path=/radio
The session parameter is important later. The stream_url is what you point your media player at after tuning. The rest isn’t too interesting. base_url and base_path are used to assemble URLs for functions like tuning and getting metadata, but they don’t seem to change. The stream_url does change, including its host.
Tuning:
Now you’ve got a session, tune to something. You need a lastfm:// URL for that. You can get these from the last.fm website everywhere you see one of the little green buttons (just hover your mouse over them) or make them yourself:
* Your neighbour station is at lastfm://user//neighbours
* Similar Artist stations are at lastfm://artist//similarartists
* Tag radio is at lastfm://globaltags/
To tune, call an URL like this (all in one line of course):
http://ws.audioscrobbler.com/radio/adjust.php?
session=&
url=&debug=0
The session is the strange character string which you got when logging in, after the “session=”. The lastfm URL needs to be entered including the lastfm:// bit. The result you get is like this:
response=OK
url=lastfm://globaltags/indie
You’ll get an error if the URL you entered isn’t valid.
Listening:
Now point your player to the stream_url you got while logging in. Radio should now play. Enjoy!
More functions
There’s more, of course:
The shoutcast stream does not contain metadata, sadly. You can get metadata of the currently playing song by calling:
http://ws.audioscrobbler.com/radio/np.php?
session=&debug=0
The result looks like:
streaming=true
discovery=-1
station=’s Neighbour Radio
station_url=http://www.last.fm/user//
stationfeed=
stationfeed_url=http://www.last.fm/user//
artist=The Doors
artist_url=http://www.last.fm/music/The+Doors
track=The Crystal Ship
track_url=http://www.last.fm/music/The+Doors/_/The+Crystal+Ship
album=The Doors of Heaven
album_url=http://www.last.fm/music/The+Doors/The+Doors+of+Heaven
albumcover_small=http://static.last.fm/coverart/
albumcover_medium=http://static.last.fm/coverart/
albumcover_large=http://static.last.fm/coverart/
trackduration=155
trackprogress=96
radiomode=1
recordtoprofile=1
It should be mostly self-explanatory...
Not all of the entries are available in every case, for example tag radio stations don’t have station_url entries. The albumcover parameter points to albumcovers at Amazon, if they are available, and to static.last.fm/coverart otherwise.
You can skip a song by calling:
http://ws.audioscrobbler.com/radio/control.php?
session=&command=skip&debug=0
To love or ban a song replace “command=skip” with “Command=love” or “command=ban” in above URL. The result is just a line with response=OK.
There are even more functions available, like enabling and disabling “Record songs to Profile”, but i did not bother to reverse-engineer them. If you did, feel free to explain them in a comment below.
Various webservices concerning searching similar artists or tags are available at ws.audioscrobbler.com for everyone to use.
Happy Radio!