annotate contrib/xchat-audacious.py @ 2749:96e7c0385973 trunk

[svn] - add stop, pause, next, prev, play functions
author nenolod
date Fri, 11 May 2007 21:19:21 -0700
parents a67712c75069
children 4df1d5552a4d
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 #
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
8
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
9 __module_name__ = "xchat-audacious"
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
10 __module_version__ = "1.0"
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
11 __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
12
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
13 from dbus import Bus, Interface
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
14 import xchat
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
15
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
16 # connect to DBus
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
17 bus = Bus(Bus.TYPE_SESSION)
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 def command_np(word, word_eol, userdata):
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
20 aud = bus.get_object('org.atheme.audacious', '/org/atheme/audacious')
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
21
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
22 # this seems to be best, probably isn't!
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
23 length = "stream"
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
24 if aud.SongLength(aud.Position()) > 0:
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
25 length = "%d:%02d" % (aud.SongLength(aud.Position()) / 60,
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
26 aud.SongLength(aud.Position()) % 60)
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
27
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
28 xchat.command("SAY [%s | %d:%02d/%s]" % (
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
29 aud.SongTitle(aud.Position()),
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
30 aud.Time() / 1000 / 60, aud.Time() / 1000 % 60,
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
31 length))
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
32
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
33 return xchat.EAT_ALL
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
34
2749
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
35 def command_next(word, word_eol, userdata):
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
36 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Next()
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
37
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
38 def command_prev(word, word_eol, userdata):
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
39 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Reverse()
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
40
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
41 def command_pause(word, word_eol, userdata):
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
42 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Pause()
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
43
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
44 def command_stop(word, word_eol, userdata):
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
45 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Stop()
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
46
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
47 def command_play(word, word_eol, userdata):
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
48 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Play()
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
49
2740
a67712c75069 [svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff changeset
50 xchat.hook_command("NP", command_np, help="Displays current playing song.")
2749
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
51 xchat.hook_command("NEXT", command_next, help="Advances in Audacious' playlist.")
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
52 xchat.hook_command("PREV", command_prev, help="Goes backwards in Audacious' playlist.")
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
53 xchat.hook_command("PAUSE", command_np, help="Toggles paused status.")
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
54 xchat.hook_command("STOP", command_np, help="Stops playback.")
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
55 xchat.hook_command("PLAY", command_np, help="Begins playback.")
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
56
96e7c0385973 [svn] - add stop, pause, next, prev, play functions
nenolod
parents: 2740
diff changeset
57 print "xchat-audacious $Id: xchat-audacious.py 4524 2007-05-12 04:19:21Z nenolod $ loaded"