From 7f9eef4ce112475de1e524f475f09d92256f7bdb Mon Sep 17 00:00:00 2001 From: Zero Cho Date: Thu, 30 May 2013 10:50:04 -0700 Subject: [PATCH] Add player support for Rdio Mac app Conflicts: powerline/segments/common.py --- powerline/segments/common.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/powerline/segments/common.py b/powerline/segments/common.py index e10108a4..f9dd288f 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -1221,6 +1221,41 @@ class NowPlayingSegment(Segment): 'elapsed': now_playing[3], 'total': now_playing[4], } + + def player_rdio(self, pl): + now_playing = self._run_cmd(['osascript', + '-e', 'tell application "System Events"', + '-e', 'set rdio_active to the count(every process whose name is "Rdio")', + '-e', 'if rdio_active is 0 then', + '-e', 'return', + '-e', 'end if', + '-e', 'end tell', + '-e', 'tell application "Rdio"', + '-e', 'set rdio_name to the name of the current track', + '-e', 'set rdio_artist to the artist of the current track', + '-e', 'set rdio_album to the album of the current track', + '-e', 'set rdio_duration to the duration of the current track', + '-e', 'set rdio_state to the player state', + '-e', 'set rdio_elapsed to the player position', + '-e', 'return rdio_name & "\n" & rdio_artist & "\n" & rdio_album & "\n" & rdio_elapsed & "\n" & rdio_duration & "\n" & rdio_state', + '-e', 'end tell']) + if not now_playing: + return + now_playing = now_playing.split('\n') + if len(now_playing) != 6: + return + state = self._convert_state(now_playing[5]) + total = self._convert_seconds(now_playing[4]) + elapsed = self._convert_seconds(float(now_playing[3]) * float(now_playing[4]) / 100) + return { + 'title': now_playing[0], + 'artist': now_playing[1], + 'album': now_playing[2], + 'elapsed': elapsed, + 'total': total, + 'state': state, + 'state_symbol': self.STATE_SYMBOLS.get(state) + } now_playing = NowPlayingSegment()