Refactor player_rdio to use the same approach spotify uses

This commit is contained in:
ZyX 2014-08-24 20:17:47 +04:00
parent 7f9eef4ce1
commit 86c9e998d1

View File

@ -1223,22 +1223,25 @@ class NowPlayingSegment(Segment):
} }
def player_rdio(self, pl): def player_rdio(self, pl):
now_playing = self._run_cmd(['osascript', status_delimiter = '-~`/='
'-e', 'tell application "System Events"', ascript = '''
'-e', 'set rdio_active to the count(every process whose name is "Rdio")', tell application "System Events"
'-e', 'if rdio_active is 0 then', set rdio_active to the count(every process whose name is "Rdio")
'-e', 'return', if rdio_active is 0 then
'-e', 'end if', return
'-e', 'end tell', end if
'-e', 'tell application "Rdio"', end tell
'-e', 'set rdio_name to the name of the current track', tell application "Rdio"
'-e', 'set rdio_artist to the artist of the current track', set rdio_name to the name of the current track
'-e', 'set rdio_album to the album of the current track', set rdio_artist to the artist of the current track
'-e', 'set rdio_duration to the duration of the current track', set rdio_album to the album of the current track
'-e', 'set rdio_state to the player state', set rdio_duration to the duration of the current track
'-e', 'set rdio_elapsed to the player position', set rdio_state to the player state
'-e', 'return rdio_name & "\n" & rdio_artist & "\n" & rdio_album & "\n" & rdio_elapsed & "\n" & rdio_duration & "\n" & rdio_state', set rdio_elapsed to the player position
'-e', 'end tell']) return rdio_name & "{0}" & rdio_artist & "{0}" & rdio_album & "{0}" & rdio_elapsed & "{0}" & rdio_duration & "{0}" & rdio_state
end tell
'''.format(status_delimiter)
now_playing = asrun(pl, ascript)
if not now_playing: if not now_playing:
return return
now_playing = now_playing.split('\n') now_playing = now_playing.split('\n')