API Doc
- Overview
- User Authentication
- Submissions (Scrobbling)
- Radio API
- Playlists
- Downloads
- REST requests
- XML-RPC requests
API Methods
- Album
- Artist
- artist.addTags
- artist.getEvents
- artist.getImages
- artist.getInfo
- artist.getPastEvents
- artist.getPodcast
- artist.getShouts
- artist.getSimilar
- artist.getTags
- artist.getTopAlbums
- artist.getTopFans
- artist.getTopTags
- artist.getTopTracks
- artist.removeTag
- artist.search
- artist.share
- artist.shout
- Auth
- Event
- Geo
- geo.getEvents
- geo.getMetroArtistChart
- geo.getMetroTrackChart
- geo.getMetroUniqueArtistChart
- geo.getMetroUniqueTrackChart
- geo.getMetroWeeklyChartlist
- geo.getTopArtists
- geo.getTopTracks
- Group
- group.getMembers
- group.getWeeklyAlbumChart
- group.getWeeklyArtistChart
- group.getWeeklyChartList
- group.getWeeklyTrackChart
- Library
- library.addAlbum
- library.addArtist
- library.addTrack
- library.getAlbums
- library.getArtists
- library.getTracks
- Playlist
- Radio
- Tag
- tag.getSimilar
- tag.getTopAlbums
- tag.getTopArtists
- tag.getTopTags
- tag.getTopTracks
- tag.getWeeklyArtistChart
- tag.getWeeklyChartList
- tag.search
- Tasteometer
- Track
- track.addTags
- track.ban
- track.getInfo
- track.getSimilar
- track.getTags
- track.getTopFans
- track.getTopTags
- track.love
- track.removeTag
- track.search
- track.share
- User
- user.getEvents
- user.getFriends
- user.getInfo
- user.getLovedTracks
- user.getNeighbours
- user.getPastEvents
- user.getPlaylists
- user.getRecentStations
- user.getRecentTracks
- user.getRecommendedArtists
- user.getRecommendedEvents
- user.getShouts
- user.getTopAlbums
- user.getTopArtists
- user.getTopTags
- user.getTopTracks
- user.getWeeklyAlbumChart
- user.getWeeklyArtistChart
- user.getWeeklyChartList
- user.getWeeklyTrackChart
- user.shout
- Venue
Radio API
Who can I stream radio to?
Any API account can only stream radio to Last.fm's paid subscribers.
Note: Due to licensing restrictions, you may not use the radio API on mobile telephones.
Tuning the Radio
The radio API requires authentication. See the authentication how-to.
Once authenticated, you can tune the radio using the radio.tune API method. This takes a station parameter that must correspond to a last.fm protocol station url. Here is the general scheme of these URLs:
lastfm://<stationtype>/<resourcename>/<station-subtype>
Here is a list of the station types currently publicly available, with example protocol URLs:
- Artist
- Similar Artists Radio (e.g. lastfm://artist/cher/similarartists )
- Top Fans Radio (e.g. lastfm://artist/cher/fans )
- User
- Library Radio (e.g. lastfm://user/last.hq/library )
- Neighbours Radio (e.g. lastfm://user/last.hq/neighbours )
- Loved Tracks Radio (e.g. lastfm://user/last.hq/loved )
- Recommendation Radio (e.g. lastfm://user/last.hq/recommended )
- Tag
- Global Tag Radio (e.g. lastfm://globaltags/disco )
Fetching Radio Content
Once the station is tuned, use the API method radio.getPlaylist to fetch content in XSPF format (see the XSPF specification). You will need to periodically pull on this XSPF service as it will provide content in small chunks. We recommend you prefetch a new XSPF before reaching the end of the last.
The XSPF will look like this:
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>+Cher+Similar+Artists</title>
<creator>Last.fm</creator>
<date>2007-11-26T17:34:38</date>
<link rel="http://www.last.fm/expiry">3600</link>
<trackList>
<track>
<location>http://play.last.fm/....mp3</location>
<title>Two People (Live)</title>
<identifier>8212510</identifier>
<album>Tina Live In Europe</album>
<creator>Tina Turner</creator>
<duration>265000</duration>
<image>http://images.amazon.com/images/...</image>
<extension application="http://www.last.fm/">
<trackauth>12345</trackauth>
<artistpage>http://www.last.fm/music/Tina+Turner</artistpage>
<albumpage>http://www.last.fm/music/...</albumpage>
<trackpage>http://www.last.fm/music/...</trackpage>
<buyTrackURL>...</buyTrackURL>
<buyAlbumURL"/>
<freeTrackURL>
</extension>
</track>
<track>
...
The expiry extension is used to communicate in seconds (from the granting of the XSPF), how long any of the track URLs in your XSPF are valid for. If you request any tracks after this expiry period you will receive errors from our streaming service (see below).
Note the extension node, which holds last.fm specific information relating to the track.
The trackauth extension provides information that is important for the submission of the track via the submissions api. This is a 5 digit key which can be sent in the submission call.
Use the location nodes to fetch individual tracks. All tracks must be requested once and only once, in the order supplied in the XSPF. Requesting the same track multiple times will result in an HTTP error returned from our streamers. Note that the track URLs provided will force an HTTP 302 redirect to the actual track location.
All tracks streamed are encoded as 128kbps MP3 files. We recommend clients begin playback as soon as a reasonable buffer (6-8 seconds) has been fetched. Do not attempt to store the file locally other than maintaining a reasonable buffer.
Streamer Error Codes
- HTTP 403 - Invalid ticket: You may be requesting tracks in the wrong order, your playlist may have expired or you have attempted to fetch the same track URL multiple times.
- HTTP 503 - Unexpected Error: Our streamers are not healthy. Try again later.