This space is intended for tools that make it easier to work with the API exposed by Last.fm, a popular community of music lovers.

These are not official Last.fm tools, but contributions by the community. The official documentation for that Last.fm API can be found here.

If you have any tools that might be useful for the community, drop me a note!

XML response definitions

The Last.fm API consists of some a number of web services, called though a RESTful URL, returning an XML response.

The Last.fm API documentation does show an example response, but no formal definition of the response. We created XML Schema Definitions (xsd's) from some of the responses here

geo.getEvents uses some elements for the http://www.w3.org/2003/01/geo/wgs84_pos# Geo positioning namespace. Normally, this is an RDF namespace, but to be able to use it in XML we also created an XSD for it:

Tools for PHP development

Matt Oakes wrote a PHP Last.fm API library

Tools for .Net development

A library for .Net is also available: LastFmLib.Net

Tools for Python development

Bindings for Python can be found here

Tools for Java development

There are currently 2 active projects for Java bindings: janni kovacs' Last.fm API bindings and the one in this project.

Based on the XSD's above, we generated a Java library containing:

  • Java bean classes
  • Unmarshalling (converting XML to these Java classes)
  • Calling the Last.fm API, returning unmarshalled response
The first 2 features are currently implemented by leveraging Apache jaxme, an open-source JAXB implementation.

Calling the Last.fm API is currently done with some special-purpose code. Preferably, however, we'd have this code generated based on a WSDL 2.0 definition, which has support for RESTful webservices. We have some initial work done, but so far the Axis2 Maven plugin is refusing to generate code based on it.

Downloading

Currently, get the api lib by checking out the lastfmlib project from last.fm and doing a 'mvn package'.

Example

A simple example project (web application) using the lib is also included in CVS. It demonstrates fetching some events for a certain location, and listing any of those events which include any of the top artists for a given user.

To give a taste, the meat of the application looks like this:

			User user = new UserImpl(apiKey);
			Geo geo = new GeoImpl(apiKey);

			List<ArtistType> artists = user.getTopArtists(demoModel.user, null);
			Set<String> topArtistNames = getNames(artists);
			
			for (EventType event : geo.getManyEvents(demoModel.location, null, null, null, null, 20))
			{
				for (String artist : (List<String>) event.getArtists().getArtist())
				{
					if (topArtistNames.contains(artist))
					{
						matchingEvents.add(event);
					}
				}
			}

			info("Found " + matchingEvents.size() + " matching events out of " + events.size() + " total.");
Last.fm Logo
SourceForge.net Logo
sf.net project page