# -*- encoding: latin1 -*-
import xchat
__module_name__ = "xmms" 
__module_version__ = "1.1" 
__module_description__ = "Tell what xmms is playing" 

def playing(word, word_eol, userdata):
    """This function will display what
    you are playing in the current window
    using the xmms-info pipe.
    """
    
    file = open('/tmp/xmms-info', 'r')
    xmms_playing = file.readlines()
    xmms_song = xmms_playing[-2:][0][7:-1]
    try:
        xmms_song = xmms_song.decode('utf8').encode('iso-8859-1')
    except (UnicodeError, IndexError):
        1
    context = xchat.get_context()
    context.command('me écoute ' + xmms_song)
    return xchat.EAT_ALL

xchat.hook_command("PLAYING", playing, help="Says what you're listening to in xmms in the active window")
