# # Exaile Listening Announcer - Show song infos from Exaile during a xchat session # Type "/exaile --help" for command list # ----------------------------------------------- # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ----------------------------------------------- # # Author: Simone Economo (aka eKoeS) (http://www.lineheight.net) # Email: my.ekoes@gmail.com # # http://www.gnu.org/licenses/gpl.html # __module_name__ = "Exaile Listening Announcer" __module_version__ = "1.0" __module_description__ = "Show song infos from Exaile during a xchat session" __module_author__ = "eKoeS (my.ekoes@gmail.com)" import xchat import os from UserDict import UserDict from popen2 import popen2 config = { "template": { "cmd" : "me", # e.g.: "/me [...]". If you want to show infos as normal text, simply change it to "say" "list": [ # e.g: # = "paused" OR "playing" # = "Old Man" # <artist> = "Neil Young" # <album> = "Harvest" # <lenght> = "3:24" # <position> = "%18 [0:37]" # <elapsed> = "0:37" # <percentage> = "%18" "<status> <artist> - <title>", # 0 "<status> <artist> - <title> (<album>)", # 1 "<status> <artist> - <title> (<album>) [<length>]", # 2 "<status> <artist> - <title> (<album>) [<elapsed> / <length>]", # 3 "<status> <artist> - <title> (<album>) [<percentage>, <elapsed> / <length>]", # 4 "<status> <artist> - <title> [<length>]", # 5 "<status> <artist> - <title> [<elapsed> / <length>]", # 6 ], "default": 0, "status": { # Change status text "paused": "np (paused)", "playing": "np" # i.e.: if it's "np", song status "playing" will become "np" } }, ### Don't edit below ### "tplreplacelist" : { "<status>" : "%(status)s", "<title>" : "%(title)s", "<artist>" : "%(artist)s", "<album>" : "%(album)s", "<length>" : "%(length)s", "<position>" : "%(position)s", "<elapsed>" : "%(elapsed)s", "<percentage>" : "%(percentage)s", }, "helptext" : """ Okay, guys... pay attenction. Exaile (http://www.exaile.org/) is a good (excellent!) music player, (like Amarok, but written in GTK+), so I made a simple (and fairly good) Xchat Python plugin for it. \002I'm not a nerd\002, so please remember that \002this is not a good-quality code\002. I would like to receive helpful comments in order to improve it, so feel free to do it. :-D Usage: \t--show \t\t\t\t\t\tShow song infos, in accordance with the default template \t\t--template [number] \t\tAllow to load a template different than the original \t--next \t\t\t\t\t\tSwitch to next song \t--prev \t\t\t\t\t\tSwitch to prev song \t--stop \t\t\t\t\t\tStop current song \t--play \t\t\t\t\t\tPlay current song \t--gui \t\t\t\t\t\tShow a popup with infos from the song you're playing \t--vol \t\t\t\t\t\tAllow to change volume \t\t+[value] \t\t\t\t\tIncrease \t\t-[value] \t\t\t\t\tDecrease \t--license \t\t\tAbout GPL2 license \t--author \t\t\t\tAbout script's author \t--help \t\t\t\t\t\tShow this help text Special thanks to \002Catatonic\002 for helping me translating this help text. """, } def loadTemplate(template): for key, value in config["tplreplacelist"].items(): template = (key in template) and template.replace(key, value) or template return template class Exaile(UserDict): def __init__(self): UserDict.__init__(self) def getData(self): exaile = list(popen2("exaile -q")) output = exaile[0].read() if output[-1:] != ".": output += "." # I like "." at the end of any sentence :-P if output[0:2] == "No": return output self["status"] = output.split(" self: ", 1)[0].replace("status: ","") self["title"] = output.split(" self: ", 1)[1].split(" artist: ", 1)[0] self["artist"] = output.split(" artist: ", 1)[1].split(" album: ", 1)[0] self["album"] = output.split(" album: ", 1)[1].split(" length: ", 1)[0] self["length"] = output.split(" length: ", 1)[1].split(" position: ", 1)[0] self["position"] = output.split(" position: ", 1)[1].replace("\n","") self["elapsed"] = self["position"].split("[", 1)[1].split("]", 1)[0] self["percentage"] = self["position"].split("[", 1)[0].replace(" ","") if self["status"] == "playing": self["status"] = config["template"]["status"]["playing"] elif self["status"] == "paused": self["status"] = config["template"]["status"]["paused"] return def next(self): exaile = os.system("exaile --next") def prev(self): exaile = os.system("exaile --prev") def stop(self): exaile = os.system("exaile --stop") def play(self): exaile = os.system("exaile --play") def popup(self): exaile = os.system("exaile --gui-query") def volIncr(self, param): try: exaile = os.system("exaile -i %d" % int(param)) except ValueError: return "Type an integer value!" return def volDecr(self, param): try: exaile = os.system("exaile -l %d" % int(param)) except ValueError: return "Type an integer value!" return def Announcer(word, word_eol, userdata): exaile = Exaile() flags, channel = word_eol[1], xchat.get_info("channel") if "--show" in flags: if exaile.getData() is not None: xchat.command("echo \002Error\002 %s" % exaile.getData()) return usetemplate = config["template"]["default"] if "--template" in flags: try: start = int(flags.find("--template") + len("--template") +1) usetemplate = flags[start:] try: usetemplate = int(usetemplate.split(" ", 1)[0]) except: usetemplate = int(usetemplate) except: xchat.command("echo \002Error\002 Make sure you have correctly specified a template.") return try: config["template"]["list"][usetemplate] # Does a specified template exist? except: xchat.command("echo \002Error\002 Template #%d does not exist." % usetemplate) return xchat.command("%s %s" % (config["template"]["cmd"], loadTemplate(config["template"]["list"][usetemplate]) % exaile)) elif flags == "--next": exaile.next() elif flags == "--prev": exaile.prev() elif flags == "--stop": exaile.stop() elif flags == "--play": exaile.play() elif flags == "--gui" : exaile.popup() elif flags.split()[0] == "--vol": if flags.split()[1][0] == "+": if exaile.volIncr(flags.split()[1][1:]) is not None: xchat.command("echo \002Error\002 %s" % exaile.volIncr(flags.split()[1][1:])) return elif flags.split()[1][0] == "-": if exaile.volDecr(flags.split()[1][1:]) is not None: xchat.command("echo \002Error\002 %s" % exaile.volDecr(flags.split()[1][1:])) return elif flags.split()[0] == "--license": print """ ### ABOUT GPL2 LICENSE ### This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/licenses/gpl.html """ elif flags.split()[0] == "--author": print """ ### ABOUT AUTHOR ### \002Author\002: Simone Economo (aka eKoeS) (http://www.lineheight.net) \002Email\002: my.ekoes@gmail.com """ elif flags.split()[0] == "--help": print config["helptext"] else: xchat.command("echo \002Error\002 Unknown command. Type \"/exaile --help\" for command list.") return xchat.hook_command("exaile", Announcer, help = config["helptext"]) print "Module \"%s\" v.%s loaded correctly!\nType \"/exaile --help\" for command list" % (__module_name__,__module_version__)