Mercurial > audlegacy
annotate contrib/xchat-audacious.py @ 2759:0c9bb15a4321 trunk
[svn] - encode songtitle in utf8 before passing to XChat.
author | nenolod |
---|---|
date | Fri, 11 May 2007 21:57:25 -0700 |
parents | c888facd2c0d |
children | c5dec731eff6 |
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. |
2759
0c9bb15a4321
[svn] - encode songtitle in utf8 before passing to XChat.
nenolod
parents:
2758
diff
changeset
|
9 # $Id: xchat-audacious.py 4544 2007-05-12 04:57:25Z nenolod $ |
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" |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
13 __module_version__ = "1.0" |
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 |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
16 from dbus import Bus, Interface |
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 |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
22 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
|
23 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
|
24 |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
25 # 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
|
26 length = "stream" |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
27 if aud.SongLength(aud.Position()) > 0: |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
28 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
|
29 aud.SongLength(aud.Position()) % 60) |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
30 |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
31 xchat.command("SAY [%s | %d:%02d/%s]" % ( |
2759
0c9bb15a4321
[svn] - encode songtitle in utf8 before passing to XChat.
nenolod
parents:
2758
diff
changeset
|
32 aud.SongTitle(aud.Position()).encode("utf8"), |
2740
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
33 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
|
34 length)) |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
35 |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
36 return xchat.EAT_ALL |
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
37 |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
38 def command_next(word, word_eol, userdata): |
2758 | 39 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Advance() |
2751 | 40 return xchat.EAT_ALL |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
41 |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
42 def command_prev(word, word_eol, userdata): |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
43 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Reverse() |
2751 | 44 return xchat.EAT_ALL |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
45 |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
46 def command_pause(word, word_eol, userdata): |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
47 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Pause() |
2751 | 48 return xchat.EAT_ALL |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
49 |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
50 def command_stop(word, word_eol, userdata): |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
51 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Stop() |
2751 | 52 return xchat.EAT_ALL |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
53 |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
54 def command_play(word, word_eol, userdata): |
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
55 bus.get_object('org.atheme.audacious', '/org/atheme/audacious').Play() |
2751 | 56 return xchat.EAT_ALL |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
57 |
2752
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
58 def command_send(word, word_eol, userdata): |
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
59 if len(word) < 1: |
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
60 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
|
61 return xchat.EAT_ALL |
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
62 |
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
63 aud = bus.get_object('org.atheme.audacious', '/org/atheme/audacious') |
2757
6f38159839be
[svn] - clean up command_send(). tips from deitarion.
nenolod
parents:
2756
diff
changeset
|
64 xchat.command('DCC SEND %s "%s"' % (word[1], aud.SongFilename(aud.Position()))) |
2752
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
65 return xchat.EAT_ALL |
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
66 |
2740
a67712c75069
[svn] - add an xchat script which wraps our DBus API using dbus-python.
nenolod
parents:
diff
changeset
|
67 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
|
68 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
|
69 xchat.hook_command("PREV", command_prev, help="Goes backwards in Audacious' playlist.") |
2750 | 70 xchat.hook_command("PAUSE", command_pause, help="Toggles paused status.") |
71 xchat.hook_command("STOP", command_stop, help="Stops playback.") | |
72 xchat.hook_command("PLAY", command_play, help="Begins playback.") | |
2752
1ca3b314301d
[svn] - add /SENDTRACK which can DCC the current track to a user
nenolod
parents:
2751
diff
changeset
|
73 xchat.hook_command("SENDTRACK", command_send, help="Sends the currently playing track to a user.") |
2749
96e7c0385973
[svn] - add stop, pause, next, prev, play functions
nenolod
parents:
2740
diff
changeset
|
74 |
2759
0c9bb15a4321
[svn] - encode songtitle in utf8 before passing to XChat.
nenolod
parents:
2758
diff
changeset
|
75 print "xchat-audacious $Id: xchat-audacious.py 4544 2007-05-12 04:57:25Z nenolod $ loaded" |