def is_track_playable(self, track): ''' Check if a track can be played by a client or not ''' playable = True assert_loaded(track) if track.is_local(): playable = False elif not track.availability(): playable = False return playable
def wait_until_loaded(self, spotify_object, timeout): ''' Poll a spotify object until it is loaded :param spotify_object: The spotify object to poll. :param timeout: A timeout in seconds. ''' start = time() while not spotify_object.is_loaded() and start > time() - timeout: message = "Waiting for spotify object: %s" % spotify_object self.log(message, debug = True) self.session.process_events() sleep(POLL_INTERVAL) assert_loaded(spotify_object) return spotify_object
def wait_until_loaded(self, spotify_object, timeout): ''' Poll a spotify object until it is loaded :param spotify_object: The spotify object to poll. :param timeout: A timeout in seconds. ''' start = time() while not spotify_object.is_loaded() and start > time() - timeout: message = "Waiting for spotify object: %s" % spotify_object self.log(message, debug=True) self.session.process_events() sleep(POLL_INTERVAL) assert_loaded(spotify_object) return spotify_object
def get_starred_tracks(self): ''' Return the user's starred tracks TODO this should be made async with a callback rather than assuming the starred playlist is loaded (will fail if it isn't right now). ''' self.log("Get starred") return assert_loaded(self.session.starred()) if self.session else None
def get_playlist(self, folder_id, index): playlists = self.client.get_playlists(folder_id) if len(playlists) < index + 1: return MessageContainer(header=L("MSG_TITLE_PLAYLIST_ERROR"), message=L("MSG_BODY_PLAYIST_ERROR")) playlist = playlists[index] tracks = list(playlist) Log("Get playlist: %s", playlist.name().decode("utf-8")) directory = ObjectContainer(title2=playlist.name().decode("utf-8"), view_group=ViewMode.Tracks) for track in assert_loaded(tracks): self.add_track_to_directory(track, directory) return directory
def get_playlist(self, folder_id, index): playlists = self.client.get_playlists(folder_id) if len(playlists) < index + 1: return MessageContainer( header = L("MSG_TITLE_PLAYLIST_ERROR"), message = L("MSG_BODY_PLAYIST_ERROR") ) playlist = playlists[index] tracks = list(playlist) Log("Get playlist: %s", playlist.name().decode("utf-8")) directory = ObjectContainer( title2 = playlist.name().decode("utf-8"), view_group = ViewMode.Tracks) for track in assert_loaded(tracks): self.add_track_to_directory(track, directory) return directory
def is_album_playable(self, album): ''' Check if an album can be played by a client or not ''' assert_loaded(album) return album.is_available()