-
Notifications
You must be signed in to change notification settings - Fork 1
/
banshee_xchat.py
49 lines (35 loc) · 1.43 KB
/
banshee_xchat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
from dbus import SessionBus, DBusException
import xchat
__module_name__ = "Banshee X-Chat Plugin"
__module_version__ = "1.0"
__module_description__ = "A simple X-Chat announcer for Banshee 1.5+"
__author__ = "Max Noel <maxfnoel at gee mail dot com>"
class Banshee(object):
BANSHEE_OBJECT = "org.bansheeproject.Banshee"
PLAYER_ENGINE_NODE = "/org/bansheeproject/Banshee/PlayerEngine"
def __init__(self):
session_bus = SessionBus()
self.player_engine = session_bus.get_object(self.BANSHEE_OBJECT, self.PLAYER_ENGINE_NODE)
def current_track(self):
return self.player_engine.GetCurrentTrack()
def do_track_info(word, word_eol, user_data):
"""/me the current track info."""
try:
banshee = Banshee()
except DBusException:
# Banshee not launched
xchat.prnt("Cannot comply: Banshee is not running.")
else:
track_data = banshee.current_track()
template = "say np: %(artist)s - %(name)s "
# TODO Figure out what character encoding X-Chat is using and encode to it.
# Defaulting to UTF-8 in the meantime.
xchat.command((template % track_data).encode("utf-8"))
# X-Chat doesn't know the command.
return xchat.EAT_XCHAT
media_hook = xchat.hook_command("banshee", do_track_info)
def unload(user_data):
xchat.unhook(media_hook)
xchat.hook_unload(unload)
xchat.prnt("Banshee plugin loaded.")