""" Copyright (C) 2009 Programble 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 3 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, see . """ import weechat import os import xmmsclient OUTPUT_PREFIX = "/me is listening to" OUTPUT_SUFFIX = "(XMMS2)" weechat.register("xmms2np", "programble ", "1.0", "GPL3", "Display song currently playing in XMMS2", "", "") weechat.hook_command("xmms2np", "Send currently playing song in XMMS2 to current buffer", "", "", "", "np_cmd", "") def np_cmd(data, buffer, args): global OUTPUT_PREFIX, OUTPUT_SUFFIX xmms = xmmsclient.XMMS("xmms2np") try: xmms.connect(os.getenv("XMMS_PATH")) except IOError, detail: weechat.prnt("", "xmms2np: Could not connect to XMMS2 daemon: %s" % detail) return weechat.WEECHAT_RC_OK result = xmms.playback_current_id() result.wait() if result.iserror(): weechat.prnt("", "xmms2np: Playback ID error: %s" % result.get_error()) return weechat.WEECHAT_RC_OK id = result.value() if id == 0: weechat.prnt("", "xmms2np: No song playing") return weechat.WEECHAT_RC_OK result = xmms.medialib_get_info(id) result.wait() if result.iserror(): weechat.prnt("", "xmms2np: Medialib error: %s" % result.get_error()) return weechat.WEECHAT_RC_OK minfo = result.value() artist = "Unknown" title = "Unknown" album = "Unknown" try: artist = minfo["artist"] except: pass try: title = minfo["title"] except: pass try: album = minfo["album"] except: pass weechat.command(buffer, "%s %s by %s on %s %s" % (OUTPUT_PREFIX, title, artist, album, OUTPUT_SUFFIX)) return weechat.WEECHAT_RC_OK