summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-06-05 13:19:06 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-06-05 13:19:06 +0300
commita02d999a549c8682be802dcb6e8d3b78054c04a1 (patch)
tree31bebecdad0874983c4dccb2b627a8d4d79a2701
parent018d6bd9d76f1e23ad5108f9e45415e1d10acce7 (diff)
UpdatesHEADmaster
-rwxr-xr-xaudio/xchat-mpris2.py78
-rwxr-xr-xpower/usb_autosuspend7
2 files changed, 61 insertions, 24 deletions
diff --git a/audio/xchat-mpris2.py b/audio/xchat-mpris2.py
index 5b6647e..1e23817 100755
--- a/audio/xchat-mpris2.py
+++ b/audio/xchat-mpris2.py
@@ -10,18 +10,23 @@ __module_description__ = "Fetches information from MPRIS2-compliant music player
10bus = dbus.SessionBus() 10bus = dbus.SessionBus()
11 11
12dbusNamePrefix = 'org.mpris.MediaPlayer2.' 12dbusNamePrefix = 'org.mpris.MediaPlayer2.'
13target = None
14dbusObj = bus.get_object('org.freedesktop.DBus', '/')
15for name in dbusObj.ListNames(dbus_interface='org.freedesktop.DBus'):
16 if name.startswith(dbusNamePrefix):
17 target = name
18 break
19 13
20assert target is not None 14def target_get():
15 target = None
21 16
22targetObject = bus.get_object(target, '/org/mpris/MediaPlayer2') 17 dbusObj = bus.get_object('org.freedesktop.DBus', '/')
23mpris = dbus.Interface(targetObject, dbus_interface='org.mpris.MediaPlayer2.Player') 18 for name in dbusObj.ListNames(dbus_interface='org.freedesktop.DBus'):
24properties = dbus.Interface(targetObject, dbus_interface='org.freedesktop.DBus.Properties') 19 if name.startswith(dbusNamePrefix):
20 target = name
21 break
22
23 if target is None: raise RuntimeError
24
25 targetObject = bus.get_object(target, '/org/mpris/MediaPlayer2')
26 mpris = dbus.Interface(targetObject, dbus_interface='org.mpris.MediaPlayer2.Player')
27 properties = dbus.Interface(targetObject, dbus_interface='org.freedesktop.DBus.Properties')
28
29 return mpris, properties
25 30
26def status(str): 31def status(str):
27 xchat.prnt("[%s] %s" % (getPlayerVersion(), str)) 32 xchat.prnt("[%s] %s" % (getPlayerVersion(), str))
@@ -42,20 +47,28 @@ def formatTime(time):
42 return "0:00" 47 return "0:00"
43 48
44def performAction(action): 49def performAction(action):
50 mpris, properties = target_get()
51
45 try: 52 try:
46 fn = getattr(mpris, action) 53 fn = getattr(mpris, action)
47 if fn: 54 if fn:
48 return fn() 55 return fn()
49 except dbus.exceptions.DBusException: 56 except dbus.exceptions.DBusException as e:
57 xchat.prnt(repr(e))
50 return False 58 return False
51 59
52def getProperty(interface, prop): 60def getProperty(interface, prop):
61 mpris, properties = target_get()
62
53 try: 63 try:
54 return properties.Get(interface, prop) 64 return properties.Get(interface, prop)
55 except dbus.exceptions.DBusException: 65 except dbus.exceptions.DBusException as e:
66 xchat.prnt(repr(e))
56 return False 67 return False
57 68
58def getSongInfo(): 69def getSongInfo():
70 mpris, properties = target_get()
71
59 try: 72 try:
60 data = properties.Get("org.mpris.MediaPlayer2.Player", "Metadata", utf8_strings=True) 73 data = properties.Get("org.mpris.MediaPlayer2.Player", "Metadata", utf8_strings=True)
61 74
@@ -74,14 +87,21 @@ def getSongInfo():
74 version = getProperty("org.mpris.MediaPlayer2", "Identity") 87 version = getProperty("org.mpris.MediaPlayer2", "Identity")
75 88
76 return (artist, title, album, pos, length, version) 89 return (artist, title, album, pos, length, version)
77 except dbus.exceptions.DBusException: 90 except dbus.exceptions.DBusException as e:
91 xchat.prnt(repr(e))
78 return False 92 return False
79 93
80def getPlayerVersion(): 94def getPlayerVersion():
81 try: 95 try:
96 mpris, properties = target_get()
97 except RuntimeError:
98 return None
99
100 try:
82 return getProperty("org.mpris.MediaPlayer2", "Identity") 101 return getProperty("org.mpris.MediaPlayer2", "Identity")
83 except dbus.exceptions.DBusException: 102 except dbus.exceptions.DBusException as e:
84 return "DBus Exception" 103 xchat.prnt(repr(e))
104 return None
85 105
86def mprisPlayerVersion(word, word_eol, userdata): 106def mprisPlayerVersion(word, word_eol, userdata):
87 xchat.prnt(str(getPlayerVersion())) 107 xchat.prnt(str(getPlayerVersion()))
@@ -102,6 +122,21 @@ def mprisNp(word, word_eol, userdata):
102 xchat.prnt("Error in getSongInfo()") 122 xchat.prnt("Error in getSongInfo()")
103 return xchat.EAT_ALL 123 return xchat.EAT_ALL
104 124
125def mprisNpTest(word, word_eol, userdata):
126 info = getSongInfo()
127 if not info == False:
128 s = ""
129 s = s + info[1]
130 if info[0] != "":
131 s = s + " by " + info[0]
132 if info[2] != "":
133 s = s + " [" + info[2] + "]"
134 s = s + " [{3}/{4}] with {5}".format(*info)
135 xchat.prnt(s)
136 else:
137 xchat.prnt("Error in getSongInfo()")
138 return xchat.EAT_ALL
139
105def mprisPlay(word, word_eol, userdata): 140def mprisPlay(word, word_eol, userdata):
106 try: 141 try:
107 status('Playing') 142 status('Playing')
@@ -153,10 +188,11 @@ xchat.prnt("Current media player is %s" % getPlayerVersion())
153 188
154xchat.prnt("Use /np to send information on the current song to the active channel.") 189xchat.prnt("Use /np to send information on the current song to the active channel.")
155xchat.prnt("Also provides: /next, /prev, /play, /pause, /stop, /playerversion") 190xchat.prnt("Also provides: /next, /prev, /play, /pause, /stop, /playerversion")
156xchat.hook_command("NP", mprisNp, help="Usage: NP, send information on current song to the active channel") 191xchat.hook_command("NP", mprisNp, help="Usage: NP, send information on current song to the active channel")
157xchat.hook_command("NEXT", mprisNext, help="Usage: NEXT, play next song") 192xchat.hook_command("NP_TEST", mprisNpTest, help="Usage: NP_TEST, echo information on current song to the current tab")
158xchat.hook_command("PREV", mprisPrev, help="Usage: PREV, play previous song") 193xchat.hook_command("NEXT", mprisNext, help="Usage: NEXT, play next song")
159xchat.hook_command("PLAY", mprisPlay, help="Usage: PLAY, play the music") 194xchat.hook_command("PREV", mprisPrev, help="Usage: PREV, play previous song")
160xchat.hook_command("PAUSE", mprisPause, help="Usage: PAUSE, pause the music") 195xchat.hook_command("PLAY", mprisPlay, help="Usage: PLAY, play the music")
161xchat.hook_command("STOP", mprisStop, help="Usage: STOP, hammer time!") 196xchat.hook_command("PAUSE", mprisPause, help="Usage: PAUSE, pause the music")
197xchat.hook_command("STOP", mprisStop, help="Usage: STOP, hammer time!")
162xchat.hook_command("PLAYERVERSION", mprisPlayerVersion, help="Usage: PLAYERVERSION, version of the media player you are using") 198xchat.hook_command("PLAYERVERSION", mprisPlayerVersion, help="Usage: PLAYERVERSION, version of the media player you are using")
diff --git a/power/usb_autosuspend b/power/usb_autosuspend
index 3e811be..31c2456 100755
--- a/power/usb_autosuspend
+++ b/power/usb_autosuspend
@@ -1,8 +1,9 @@
1#!/bin/sh 1#!/bin/sh
2 2
3for dev in /sys/bus/usb/devices/* ; do 3for dev in /sys/bus/usb/devices/usb4 ; do
4 echo Setting $dev to auto 4 echo -n "Setting $dev to auto... "
5 echo auto > $dev/power/control 5 echo auto > $dev/power/control &&
6 echo "Set to `cat $dev/power/control`"
6 done 7 done
7 8
8exit 0 9exit 0