From 340f73eff0c2ffc9d10ddd0edf315f80d22c40a3 Mon Sep 17 00:00:00 2001 From: "chester755@googlemail.com" Date: Fri, 3 Mar 2017 17:45:11 -0600 Subject: [PATCH 1/2] Add iTunes player segment Squashed commits - Fixed and redid itunes player - change the player style - Fix all the problems and removed the useless comments - Fix all the problems and removed the useless comments - Remove the truncation to the strings - removed the .DS_Store - correct the indentation I hate emacs now - correct the indentations --- powerline/segments/common/players.py | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/powerline/segments/common/players.py b/powerline/segments/common/players.py index 32277a67..ae1b32ce 100644 --- a/powerline/segments/common/players.py +++ b/powerline/segments/common/players.py @@ -477,3 +477,54 @@ Requires ``osascript`` available in $PATH. {0} ''').format(_common_args.format('rdio'))) + + +class ITunesPlayerSegment(PlayerSegment): + def get_player_status(self, pl): + status_delimiter = '-~`/=' + ascript = ''' + tell application "System Events" + set process_list to (name of every process) + end tell + + if process_list contains "iTunes" then + tell application "iTunes" + if player state is playing then + set t_title to name of current track + set t_artist to artist of current track + set t_album to album of current track + set t_duration to duration of current track + set t_elapsed to player position + set t_state to player state + return t_title & "{0}" & t_artist & "{0}" & t_album & "{0}" & t_elapsed & "{0}" & t_duration & "{0}" & t_state + end if + end tell + end if + '''.format(status_delimiter) + now_playing = asrun(pl, ascript) + if not now_playing: + return + now_playing = now_playing.split(status_delimiter) + if len(now_playing) != 6: + return + title, artist, album = now_playing[0], now_playing[1], now_playing[2] + state = _convert_state(now_playing[5]) + total = _convert_seconds(now_playing[4]) + elapsed = _convert_seconds(now_playing[3]) + return { + 'title': title, + 'artist': artist, + 'album': album, + 'total': total, + 'elapsed': elapsed, + 'state': state + } + + +itunes = with_docstring(ITunesPlayerSegment(), +('''Return iTunes now playing information + +Requires ``osascript``. + +{0} +''').format(_common_args.format('itunes'))) From f1014e414f3811def303fd96fedff1d797f9e156 Mon Sep 17 00:00:00 2001 From: Foo Date: Tue, 7 Mar 2017 02:54:33 +0300 Subject: [PATCH 2/2] Clean space-only line --- powerline/segments/common/players.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerline/segments/common/players.py b/powerline/segments/common/players.py index ae1b32ce..ccbf116b 100644 --- a/powerline/segments/common/players.py +++ b/powerline/segments/common/players.py @@ -486,7 +486,7 @@ class ITunesPlayerSegment(PlayerSegment): tell application "System Events" set process_list to (name of every process) end tell - + if process_list contains "iTunes" then tell application "iTunes" if player state is playing then