annotate contrib/xchat-audacious.py @ 4887:0ddbd0025174 default tip

added libaudtag. (not used yet.)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 05 May 2010 18:26:06 +0900
parents 548a1db694e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
1 #
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
2 # X-Chat Audacious for Audacious 1.4 and later
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
3 # This uses the native Audacious D-Bus interface.
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
4 #
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
5 # To consider later:
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
6 # - support org.freedesktop.MediaPlayer (MPRIS)?
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
7 #
2752
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
8 # This script is in the public domain.
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
9 # $Id: xchat-audacious.py 4574 2007-05-16 07:46:17Z deitarion $
2752
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
10 #
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
11
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
12 __module_name__ = "xchat-audacious"
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
13 __module_version__ = "1.0.1"
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
14 __module_description__ = "Get NP information from Audacious"
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
15
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
16 from dbus import Bus, DBusException
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
17 import xchat
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
18
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
19 # connect to DBus
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
20 bus = Bus(Bus.TYPE_SESSION)
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
21
2772
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
22 def get_aud():
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
23 try:
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
24 return bus.get_object('org.atheme.audacious', '/org/atheme/audacious')
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
25 except DBusException:
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
26 print "\x02Either Audacious is not running or you have something wrong with your D-Bus setup."
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
27 return None
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
28
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
29 def command_np(word, word_eol, userdata):
2772
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
30 aud = get_aud()
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
31 if aud:
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
32 pos = aud.Position()
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
33
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
34 length = aud.SongLength(pos)
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
35 length = (length > 0) and ("%d:%02d" % (length / 60, length % 60)) or "stream"
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
36
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
37 playSecs = aud.Time() / 1000
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
38 xchat.command("SAY [%s | %d:%02d/%s]" % (
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
39 aud.SongTitle(pos).encode("utf8"),
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
40 playSecs / 60, playSecs % 60, length))
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
41 return xchat.EAT_ALL
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
42
2772
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
43 def makeVoidCommand(cmd):
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
44 def callback(word, word_eol, userdata):
2773
cd9311fed796 [svn] A few more xchat-audacious.py corrections:
deitarion
parents: 2772
diff changeset
45 getattr(get_aud(), cmd, lambda: None)()
2772
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
46 return xchat.EAT_ALL
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
47 return callback
2749
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
48
2752
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
49 def command_send(word, word_eol, userdata):
2772
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
50 if len(word) < 2:
2752
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
51 print "You must provide a user to send the track to."
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
52 return xchat.EAT_ALL
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
53
2772
3c2786bbcf36 [svn] Fixes for xchat-audacious.py:
deitarion
parents: 2764
diff changeset
54 aud = get_aud()
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
55 if aud:
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
56 xchat.command('DCC SEND %s "%s"' % (word[1], aud.SongFilename(aud.Position()).encode("utf8")))
2752
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
57 return xchat.EAT_ALL
1ca3b314301d [svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents: 2751
diff changeset
58
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
59 xchat.hook_command("NP", command_np, help="Displays current playing song.")
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
60 xchat.hook_command("NEXT", makeVoidCommand('Advance'), help="Advances in Audacious' playlist.")
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
61 xchat.hook_command("PREV", makeVoidCommand('Reverse'), help="Goes backwards in Audacious' playlist.")
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
62 xchat.hook_command("PAUSE", makeVoidCommand('Pause'), help="Toggles paused status.")
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
63 xchat.hook_command("STOP", makeVoidCommand('Stop'), help="Stops playback.")
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
64 xchat.hook_command("PLAY", makeVoidCommand('Play'), help="Begins playback.")
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
65 xchat.hook_command("SENDTRACK", command_send, help="Syntax: /SENDTRACK <nick>\nSends the currently playing track to a user.")
2749
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
66
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
67 # IRC+PP support section
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
68
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
69 # XChat is lame and does not give us a server list.
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
70 def get_servers():
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
71 chanlist = xchat.get_list("channels")
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
72 servlist = []
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
73
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
74 for i in chanlist:
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
75 if i.server not in servlist:
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
76 servlist.append(i.server)
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
77
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
78 return servlist
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
79
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
80 ignore_services = 0;
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
81 def ignore_service_errors_cb(word, word_eol, userdata):
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
82 global ignore_services
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
83
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
84 if ignore_services == 1:
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
85 return xchat.EAT_ALL
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
86
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
87 return xchat.EAT_NONE
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
88
2858
548a1db694e6 Disable presence stuff for now.
William Pitcock <nenolod@atheme.org>
parents: 2852
diff changeset
89 #xchat.hook_print("Notice", ignore_service_errors_cb)
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
90
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
91 def unset_ignore_services(userdata=None):
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
92 global ignore_services
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
93
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
94 ignore_services = 0
2852
William Pitcock <nenolod@atheme.org>
parents: 2851
diff changeset
95 return 1
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
96
2850
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
97 last_title = None
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
98
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
99 def presence_notification_dispatch(userdata=None):
2850
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
100 global ignore_services, last_title
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
101
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
102 aud = get_aud()
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
103
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
104 ignore_services = 1
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
105 if aud:
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
106 pos = aud.Position()
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
107
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
108 title = aud.SongTitle(pos).encode("utf8")
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
109
2850
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
110 if title != last_title:
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
111 slist = get_servers()
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
112 for i in slist:
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
113 ctx = xchat.find_context(i)
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
114
2850
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
115 ctx.command("nickserv set qproperty np %s" % (title))
b1390d9f35bf Some more improvements.
William Pitcock <nenolod@atheme.org>
parents: 2849
diff changeset
116
2852
William Pitcock <nenolod@atheme.org>
parents: 2851
diff changeset
117 last_title = title
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
118
2849
97dc42683fc6 Fix some bugs.
William Pitcock <nenolod@atheme.org>
parents: 2847
diff changeset
119 return 1
97dc42683fc6 Fix some bugs.
William Pitcock <nenolod@atheme.org>
parents: 2847
diff changeset
120
2858
548a1db694e6 Disable presence stuff for now.
William Pitcock <nenolod@atheme.org>
parents: 2852
diff changeset
121 #presence_notification_dispatch()
548a1db694e6 Disable presence stuff for now.
William Pitcock <nenolod@atheme.org>
parents: 2852
diff changeset
122 #xchat.hook_timer(3000, presence_notification_dispatch)
548a1db694e6 Disable presence stuff for now.
William Pitcock <nenolod@atheme.org>
parents: 2852
diff changeset
123 #xchat.hook_timer(500, unset_ignore_services)
2847
7b4b8e135cb9 Add IRC+PP support.
William Pitcock <nenolod@atheme.org>
parents: 2774
diff changeset
124
2774
57363f3ded79 [svn] xchat-audacious.py:
deitarion
parents: 2773
diff changeset
125 print "xchat-audacious $Id: xchat-audacious.py 4574 2007-05-16 07:46:17Z deitarion $ loaded"