Merge branch 'pr-1732' into develop

Closes #1732
This commit is contained in:
Foo 2017-03-07 02:55:38 +03:00
commit 0caef54a85
1 changed files with 51 additions and 0 deletions

View File

@ -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')))