X-Chat 2 Now Playing Plugin for Quod Libet

I'm using Quod Libet as music player on Ubuntu now since most of the other players weren't to my likes. XMMS and Audacious are too simple; I need my media library. I don't like Rythmbox's media library, I don't quite remember why though. Amarok. It's bloatware (plus it's for KDE desktops).

Quod Libet has a simple media libaray that lets me type into a search box and automatically will use the results as playlist. If I want to listen to one specific song now and then listen to everything again i can simply queue a song. If I want to listen to an Album i open the album view.

But there was a problem: I couldn't spam IRC with now-playing-statusmessages; for Audacious there was a plugin, for Quod Libet there wasn't. Simple solution, you might have guessed it: a Python script like my Shell Plugin. The easiest way to get the title, artist and album of the currently playing song I found was using the JEP-118 Plugin of Quod Libet which produces a Jabber User Tunes file. I parsed it with xml.dom.minidom and that was about it. Here's the result:

#!/usr/bin/env python
# coding=UTF-8

__module_name__ = "Quod Libet Now Playing (Jabber)"
__module_version__ = "1.0"
__module_description__ = "now playing plugin that parses ~/quodlibet/jabber"

import xchat, os
import xml.dom.minidom

def nowplaying(word, word_eol, userdata):
    ctx = xchat.get_context()
    if word[0] == 'qlnp' and os.path.exists(os.environ['HOME']+'/.quodlibet/jabber'):
        dom = xml.dom.minidom.parse(os.environ['HOME']+'/.quodlibet/jabber')
            artist = dom.getElementsByTagName('artist')[0].childNodes[0].data
            artist = 'No Artist'
            title = dom.getElementsByTagName('title')[0].childNodes[0].data
            title = 'No Title'
            album = dom.getElementsByTagName('source')[0].childNodes[0].data
            album = 'No Album'
        command = 'me np: %s - %s' % (artist, title)
        return xchat.EAT_ALL
    return xchat.EAT_NONE

xchat.hook_command("qlnp", nowplaying)
xchat.prnt('Quod Libet Now Playing Plugin Loaded')

Edit: For ctx.command() Python seems to treat the passed argument (which in fact is unicode) as ascii string and tries to convert it to unicode which fails in: »UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 30: ordinal not in range(128)«. I have no idea why and it sucks but encoding the UTF-8 makes it work.

Edit #2: Empty tags (of wrong/not tagged music files) caused an exception, just wrapped a try except around the critical part.