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
This commit is contained in:
chester755@googlemail.com 2017-03-03 17:45:11 -06:00 committed by Foo
parent 4c68f773aa
commit 340f73eff0
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')))