/
amarok.py
142 lines (124 loc) · 3.72 KB
/
amarok.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# vim: set noexpandtab ts=8 sw=8:
from __future__ import absolute_import
__kupfer_name__ = _("Amarok")
__kupfer_actions__ = ("StopAfterCurrent", "ShowOSD", "Play",
"Pause", "Next", "Previous", "Mute")
__description__ = _("Control Amarok media player.")
__version__ = "2010-10-22"
__author__ = "Andreas Kotowicz <andreas.kotowicz@gmail.com>"
'''
TODO (don't know how to do these things):
- start amarok if not running and user hits "play" (via dbus)
'''
import dbus
from kupfer.objects import Action, AppLeaf
from kupfer import icons, pretty
from kupfer import plugin_support
plugin_support.check_dbus_connection()
SERVICE_NAME = "org.kde.amarok"
OBJECT_PATH = "/Player"
def _get_amarok():
""" Return the dbus proxy object for Amarok
we will activate it over d-bus (start if not running)
"""
bus = dbus.SessionBus()
try:
amarok_obj = bus.get_object(SERVICE_NAME, OBJECT_PATH)
except dbus.DBusException, e:
pretty.print_error(__name__, e)
return
return amarok_obj
class StopAfterCurrent (Action):
def __init__(self):
Action.__init__(self, name=_("StopAfterCurrent"))
def activate(self, leaf, obj):
_get_amarok().StopAfterCurrent()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Stop Amarok playback after current song")
def get_icon_name(self):
return "media-playback-stop"
class ShowOSD (Action):
def __init__(self):
Action.__init__(self, name=_("Show OSD"))
def activate(self, leaf, obj):
_get_amarok().ShowOSD()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Show Amarok OSD")
def get_gicon(self):
return icons.ComposedIcon("dialog-information", "audio-x-generic")
def get_icon_name(self):
return "dialog-information"
class Play (Action):
def __init__(self):
Action.__init__(self, name=_("Play"))
def activate(self, leaf, obj):
_get_amarok().Play()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Resume playback in Amarok")
def get_icon_name(self):
return "media-playback-start"
class Pause (Action):
def __init__(self):
Action.__init__(self, name=_("Pause"))
def activate(self, leaf, obj):
_get_amarok().Pause()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Pause playback in Amarok")
def get_icon_name(self):
return "media-playback-pause"
class Next (Action):
def __init__(self):
Action.__init__(self, name=_("Next"))
def activate(self, leaf, obj):
_get_amarok().Next()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Jump to next track in Amarok")
def get_icon_name(self):
return "media-skip-forward"
class Previous (Action):
def __init__(self):
Action.__init__(self, name=_("Previous"))
def activate(self, leaf, obj):
_get_amarok().Prev()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Jump to previous track in Amarok")
def get_icon_name(self):
return "media-skip-backward"
class Mute (Action):
def __init__(self):
Action.__init__(self, name=_("Mute"))
def activate(self, leaf, obj):
_get_amarok().Mute()
def item_types(self):
yield AppLeaf
def valid_for_item(self, leaf):
return leaf.get_id() == "kde4-amarok"
def get_description(self):
return _("Mute / Unmute Amarok")
def get_icon_name(self):
return "audio-volume-muted"
# EOF