def updateTrack(self): """ Get a current player state. """ print "-- Calling Service: Update" try: resp = self.call("") if (self.debug): print resp if ('item' in resp): self.oh.sendCommand('spotify_current_track', getJSONValue(resp, ['item','name'])) self.oh.sendCommand('spotify_current_artist', getJSONValue(resp, ['item', 'artists', 0, 'name'])) self.oh.sendCommand('spotify_current_cover', getJSONValue(resp, ['item', 'album', 'images', 1, 'url'])) self.oh.sendCommand('spotify_current_duration', getJSONValue(resp, ['item', 'duration_ms'])) self.oh.sendCommand('spotify_current_progress', getJSONValue(resp, ['progress_ms'])) self.oh.sendCommand('spotify_current_progress', getJSONValue(resp, ['progress_ms'])) self.oh.sendCommand('spotify_current_playing', mapValues(getJSONValue(resp, ['is_playing']), { 'True': 'ON', 'False': 'OFF' })) self.oh.sendCommand('spotify_current_device', getJSONValue(resp, ['device', 'name'])) self.oh.sendCommand('spotify_current_device_id', getJSONValue(resp, ['device', 'id'])) print " -> Success" else: print " -> Item node missing from response :(" except: print " -> Failure: ", sys.exc_info()[0] resp = "" return resp
def update(self): """ Get a current player state. """ print("-- Calling Service: Update") try: resp = self.call("") if (self.debug): print(resp) if ('item' in resp): self.oh.sendCommand('spotify_current_track', getJSONValue(resp, ['item', 'name'])) self.oh.sendCommand( 'spotify_current_artist', getJSONValue(resp, ['item', 'artists', 0, 'name'])) self.oh.sendCommand( 'spotify_current_cover', getJSONValue(resp, ['item', 'album', 'images', 1, 'url'])) self.oh.sendCommand( 'spotify_current_duration', getJSONValue(resp, ['item', 'duration_ms'])) self.oh.sendCommand('spotify_current_progress', getJSONValue(resp, ['progress_ms'])) self.oh.sendCommand( 'spotify_current_playing', mapValues(getJSONValue(resp, ['is_playing']), { 'True': 'ON', 'False': 'OFF' })) self.oh.sendCommand('spotify_current_device', getJSONValue(resp, ['device', 'name'])) self.oh.sendCommand( 'spotify_current_volume', getJSONValue(resp, ['device', 'volume_percent'])) self.oh.sendCommand('spotify_current_context_uri', getJSONValue(resp, ['context', 'uri'])) self.oh.sendCommand('spotify_current_device_id', getJSONValue(resp, ['device', 'id'])) duration = getJSONValue(resp, ['item', 'duration_ms']) progress = getJSONValue(resp, ['progress_ms']) if (duration is not None and progress is not None): progress_percent = round( float(progress) / float(duration) * 100, 2) else: progress_percent = 0 self.oh.sendCommand('spotify_current_progress_percent', progress_percent) print(" -> Success") else: print(" -> Item node missing from response :(") except: print(" -> Failure: ", sys.exc_info()[0]) resp = "" return resp
def update(self): """ Get a current player state. Dont run this straight after a change, you get back old results overwriting anything done locally """ print "-- Calling Service: Update" try: resp = self.call("") if (self.debug): print resp if ('item' in resp): self.oh.sendCommand('spotify_current_track', getJSONValue(resp, ['item', 'name'])) self.oh.sendCommand( 'spotify_current_artist', getJSONValue(resp, ['item', 'artists', 0, 'name'])) self.oh.sendCommand( 'spotify_current_cover', getJSONValue(resp, ['item', 'album', 'images', 1, 'url'])) self.oh.sendCommand( 'spotify_current_duration', getJSONValue(resp, ['item', 'duration_ms'])) self.oh.sendCommand('spotify_current_progress', getJSONValue(resp, ['progress_ms'])) self.oh.sendCommand( 'spotify_current_update_time', time.strftime("%Y-%m-%dT%H:%M:%S.000+0000", time.gmtime(time.time()))) self.oh.sendCommand( 'spotify_current_playing', mapValues(getJSONValue(resp, ['is_playing']), { 'True': 'ON', 'False': 'OFF' })) self.oh.sendCommand('spotify_current_device', getJSONValue(resp, ['device', 'name'])) self.oh.sendCommand( 'spotify_current_volume', getJSONValue(resp, ['device', 'volume_percent'])) self.oh.sendCommand('spotify_current_device_id', getJSONValue(resp, ['device', 'id'])) self.oh.sendCommand('spotify_current_context_uri', getJSONValue(resp, ['context', 'uri'])) self.oh.sendCommand('spotify_playing', getJSONValue(resp, ['context', 'type'])) print " -> Success" else: print " -> Playing local file no details available" except: print " -> Failure: ", sys.exc_info()[0] resp = "" return resp
def update(self): """ Get a current player state. """ try: resp = self.call("") if ('item' in resp): self.oh.sendCommand('spotify_current_track', getJSONValue(resp, ['item', 'name'])) self.oh.sendCommand( 'spotify_current_artist', getJSONValue(resp, ['item', 'artists', 0, 'name'])) self.oh.sendCommand( 'spotify_current_cover', getJSONValue(resp, ['item', 'album', 'images', 1, 'url'])) self.oh.sendCommand( 'spotify_current_duration', getJSONValue(resp, ['item', 'duration_ms'])) self.oh.sendCommand('spotify_current_progress', getJSONValue(resp, ['progress_ms'])) self.oh.sendCommand( 'spotify_current_playing', mapValues(getJSONValue(resp, ['is_playing']), { 'True': 'ON', 'False': 'OFF' })) self.oh.sendCommand('spotify_current_device', getJSONValue(resp, ['device', 'name'])) self.oh.sendCommand( 'spotify_current_volume', getJSONValue(resp, ['device', 'volume_percent'])) self.oh.sendCommand('spotify_current_context_uri', getJSONValue(resp, ['context', 'uri'])) self.oh.sendCommand('spotify_current_device_id', getJSONValue(resp, ['device', 'id'])) duration = getJSONValue(resp, ['item', 'duration_ms']) progress = getJSONValue(resp, ['progress_ms']) if (duration is not None and progress is not None): progress_percent = round( float(progress) / float(duration) * 100, 2) else: progress_percent = 0 self.oh.sendCommand('spotify_current_progress_percent', progress_percent) else: pass except: resp = "" return resp