What do you listen to?

Apr 1, 2009

I love music, I love making music and I love listening to music, but I always hate the question "what do you listen to?" I don't want to answer with the elitist "I listen to bands that don't even exist yet", but I still feel like there is more to it than just "Indie/Alternative Rock". I tried getting statistics from my last.fm account into wordle to see how I can express this visually. The result is interesting and looks pretty cool, here's how I did it.

First, we need to get the data, and last.fm provides a nice API for that. I encourage you to look through the documentation to see the full potential, but for now we just need the following data: my top artists, with the playcount for each. Get the XML data from the following URL:

http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=flobruit&api_key=b25b959554ed76058ac220b7b2e0a026

Of course you want to replace 'flobruit' with your own username. The API key is the one used to demonstrate the functionality, if you want to build your own application you need to get your own key (it's quick and painless).

The XML file that we get has more information than what we need, and we want to have it in a format that wordle can understand. There are more advanced ways to do this, including libraries in a variety of programming languages, but for now we can simply use regular expressions. I'm familiar with PHP's posix regular expressions, and I'm lazy so I used an online regular expression tester with the following data:

Regular expression (all in one line): @(.*)(.*\n)*?.*(.*).*\n(.*\n)*?.*@

Data: Just paste the content of your XML file

Replacement: $1:$3

Submit the form. We now get pairs of artist names and play counts, and we can just ignore what remains of the XML file at the top and bottom, to get something like this:

Andrew Bird:282 Kings of Convenience:260 Muse:200 [...] R.E.M.:31 Elliott Smith:31

Now we can just copy this text and put it into wordle's advanced input form, click "Go", and we get something like this. Play around with the font, colors and layout until you get it to look the way you want; that in itself might already tell something about what kind of music you listen to :-).

Now if you want to save this picture, click on the "Print" button and save it as a PDF instead of sending it to a printer (if your OS doesn't let you do that, get a better OS). If you need a bitmap, just open the pdf with a graphic editor like Photoshop or Gimp and save it in the appropriate format.