def player_spotify_apple_script(self, pl): ascript = ''' tell application "System Events" set process_list to (name of every process) end tell if process_list contains "Spotify" then tell application "Spotify" if player state is playing or player state is paused then set track_name to name of current track set artist_name to artist of current track set album_name to album of current track set track_length to duration of current track set trim_length to 40 set now_playing to player state & album_name & artist_name & track_name & track_length if length of now_playing is less than trim_length then set now_playing_trim to now_playing else set now_playing_trim to characters 1 thru trim_length of now_playing as string end if else return player state end if end tell else return "stopped" end if ''' spotify = asrun(pl, ascript) if not asrun: return None spotify_status = spotify.split(", ") state = self._convert_state(spotify_status[0]) if state == 'stop': return None return { 'state': state, 'state_symbol': self.STATE_SYMBOLS.get(state), 'album': spotify_status[1], 'artist': spotify_status[2], 'title': spotify_status[3], 'total': self._convert_seconds(int(spotify_status[4])) }
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 "Spotify" then tell application "Spotify" if player state is playing or player state is paused then set track_name to name of current track set artist_name to artist of current track set album_name to album of current track set track_length to duration of current track set now_playing to "" & player state & "{0}" & album_name & "{0}" & artist_name & "{0}" & track_name & "{0}" & track_length return now_playing else return player state end if end tell else return "stopped" end if """.format( status_delimiter ) spotify = asrun(pl, ascript) if not asrun: return None spotify_status = spotify.split(status_delimiter) state = _convert_state(spotify_status[0]) if state == "stop": return None return { "state": state, "album": spotify_status[1], "artist": spotify_status[2], "title": spotify_status[3], "total": _convert_seconds(int(spotify_status[4])), }
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 "Spotify" then tell application "Spotify" if player state is playing or player state is paused then set track_name to name of current track set artist_name to artist of current track set album_name to album of current track set track_length to duration of current track set now_playing to "" & player state & "{0}" & album_name & "{0}" & artist_name & "{0}" & track_name & "{0}" & track_length & "{0}" & player position return now_playing else return player state end if end tell else return "stopped" end if '''.format(status_delimiter) spotify = asrun(pl, ascript) if not asrun: return None spotify_status = spotify.split(status_delimiter) state = _convert_state(spotify_status[0]) if state == 'stop': return None return { 'state': state, 'album': spotify_status[1], 'artist': spotify_status[2], 'title': spotify_status[3], 'total': _convert_seconds(int(spotify_status[4])/1000), 'elapsed': _convert_seconds(spotify_status[5]), }
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 }
def _get_itunes_status(pl): status_delimiter = '-~`/=' ascript = ''' tell application "System Events" set itunes_active to the count(every process whose name is "iTunes") if itunes_active is 0 then return end if end tell tell application "iTunes" set player_state to player state set track_name to name of current track set artist_name to artist of current track set album_name to album of current track set trim_length to 40 set music_duration to the duration of the current track set music_elapsed to the player position return track_name & "{0}" & artist_name & "{0}" & album_name & "{0}" & music_elapsed & "{0}" & music_duration & "{0}" & player_state end tell '''.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 state = _convert_state(now_playing[5]) total = _convert_seconds(now_playing[4]) elapsed = _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, }
def _get_itunes_status(pl): status_delimiter = '-~`/=' ascript = ''' tell application "System Events" set itunes_active to the count(every process whose name is "iTunes") if itunes_active is 0 then return end if end tell tell application "iTunes" set player_state to player state set track_name to name of current track set artist_name to artist of current track set album_name to album of current track set trim_length to 40 set music_duration to the duration of the current track set music_elapsed to the player position return track_name & "{0}" & artist_name & "{0}" & album_name & "{0}" & music_elapsed & "{0}" & music_duration & "{0}" & player_state end tell '''.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 state = _convert_state(now_playing[5]) total = _convert_seconds(now_playing[4]) elapsed = _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, }
def get_player_status(self, pl): status_delimiter = "-~`/=" ascript = """ tell application "System Events" set rdio_active to the count(every process whose name is "Rdio") if rdio_active is 0 then return end if end tell tell application "Rdio" set rdio_name to the name of the current track set rdio_artist to the artist of the current track set rdio_album to the album of the current track set rdio_duration to the duration of the current track set rdio_state to the player state set rdio_elapsed to the player position 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: return now_playing = now_playing.split(status_delimiter) if len(now_playing) != 6: return state = _convert_state(now_playing[5]) total = _convert_seconds(now_playing[4]) elapsed = _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, }
def player_rdio(self, pl): status_delimiter = '-~`/=' ascript = ''' tell application "System Events" set rdio_active to the count(every process whose name is "Rdio") if rdio_active is 0 then return end if end tell tell application "Rdio" set rdio_name to the name of the current track set rdio_artist to the artist of the current track set rdio_album to the album of the current track set rdio_duration to the duration of the current track set rdio_state to the player state set rdio_elapsed to the player position 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: return now_playing = now_playing.split(status_delimiter) if len(now_playing) != 6: return state = _convert_state(now_playing[5]) total = _convert_seconds(now_playing[4]) elapsed = _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, }
def player_rdio(self, pl): status_delimiter = '-~`/=' ascript = ''' tell application "System Events" set rdio_active to the count(every process whose name is "Rdio") if rdio_active is 0 then return end if end tell tell application "Rdio" set rdio_name to the name of the current track set rdio_artist to the artist of the current track set rdio_album to the album of the current track set rdio_duration to the duration of the current track set rdio_state to the player state set rdio_elapsed to the player position 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: 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) }