# -*- encoding: latin1 -*-
import xchat
from os import popen
__module_name__ = "rhythmbox" 
__module_version__ = "1.1" 
__module_description__ = "Tell what rhythmbox is playing" 

def playing(word, word_eol, userdata):
    """This function will display what
    you are playing in the current window
    """
    
    file = popen('rhythmbox-client --print-playing --print-playing-format "%tt - %ta"', 'r')
    rhythmbox_playing = file.readline()
    file.close()
    rhythmbox_song = rhythmbox_playing.rstrip('\n')
    try:
        rhythmbox_song = rhythmbox_song.decode('utf8').encode('iso-8859-1')
    except (UnicodeError, IndexError):
        1
    context = xchat.get_context()
    context.command('me écoute ' + rhythmbox_song)
    return xchat.EAT_ALL

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