Timur Izhbulatov — Independent Electronic Music

Fixing Last.fm tags using Python standard library

Mon, 22 Jan 2007 in Tech stuff | permalink

htmlparser httplib last.fm python tagging xml-rpc

Updated 2008-08-15. Works with new Last.fm.

I've written a Python program for renaming tags on Last.fm.

English is my second language but there are many "international" words which have either Greek or Latin roots (or those which have simply been adopted from English by other languages). On the one hand, these words can be understood by many people even without any prior language skills. On the other hand, these words can prove to be a trap! For example, the word "address" which has two double consonants in the English version but doesn't have any in the Russian version (адрес == adres). Similarly, the word "office" (офис == ofis) which doesn't have the double "f" in Russian.

This repretition of consonants caused me to run into a bit of a problem on Last.fm. I created a Last.fm tag station including some decent tracks with a more or less aggressive mood. You know, sometimes it's good have that kind of music in your playlist. Unfortunately, when I first created the station, I used the Russian version of the word "aggression" (i.e. single 'g') and the station started to grow up with that wrong tag name! Shame on me =(

I have since discovered that other people have run into a similar problem of misnamed Last.fm tags. To my knowledge, no other utilities like this exist so I created my own. It uses nothing but Python standard library (md5, xmlrpclib, httplib, HTMLParser) and can be used almost anywhere where you can run Python.

Download my Last.fm tag renaming utility and read the comments in the source code if you want to learn more. Pay attention to the authentication part; it's a little tricky. Note that the MD5 hex digest of the password string is used! Also this example shows limitations of the Last.fm XML-RPC API. I was forced to parse HTML page instead of XML-RPC response. (I hope someday we will be able to do everything through XML-RPC!)