def _load_container(self): #Wait for the container to be fully loaded self.__conditions.add_condition(self.__container.is_loaded) current_task().condition_wait(self.__conditions) #Fill the container with unseen playlists self._add_missing_playlists() #Add a load check for each playlist for item in self.__playlists: if item is not None and not item.is_loaded(): self._check_playlist(item) #Wait until all conditions become true current_task().condition_wait(self.__conditions, self.__container.num_playlists() * 5) #Set the status of the loader self.__is_loaded = True #Check and log errors for not loaded playlists for idx, item in enumerate(self.__playlists): if item is not None and item.has_errors(): get_logger().error('Playlist #%s failed loading.' % idx) #Finally tell the gui we are done xbmc.executebuiltin("Action(Noop)")
def _load_container(self): #Wait for the container to be fully loaded self.__conditions.add_condition(self.__container.is_loaded) current_task().condition_wait(self.__conditions) #Fill the container with unseen playlists self._add_missing_playlists() #Add a load check for each playlist for item in self.__playlists: if item is not None and not item.is_loaded(): self._check_playlist(item) #Wait until all conditions become true current_task().condition_wait( self.__conditions, self.__container.num_playlists() * 5 ) #Set the status of the loader self.__is_loaded = True #Check and log errors for not loaded playlists for idx, item in enumerate(self.__playlists): if item is not None and item.has_errors(): get_logger().error('Playlist #%s failed loading.' % idx) #Finally tell the gui we are done xbmc.executebuiltin("Action(Noop)")
def _wait_for_album_list(self): #Add the artistbrowse callbacks self.__artistbrowse = artistbrowse.Artistbrowse( self.__session, self.__artist, BrowseType.NoTracks, ArtistCallbacks(self) ) if not self.__artistbrowse.is_loaded(): current_task().condition_wait( self.__artistbrowse.is_loaded, 60 # Should be enough? )
def _wait_for_album_list(self): #Add the artistbrowse callbacks self.__artistbrowse = artistbrowse.Artistbrowse( self.__session, self.__artist, BrowseType.NoTracks, ArtistCallbacks(self) ) if not self.__artistbrowse.is_loaded(): current_task().condition_wait( self.__artistbrowse.is_loaded, 60 #Should be enough? )
def _wait_for_album_list(self): #Add the artistbrowse callbacks self.__artistbrowse = ArtistBrowser( self.__session, self.__artist, ArtistBrowserType.NO_TRACKS, ArtistCallbacks(self).artistbrowse_complete ) if not self.__artistbrowse.is_loaded: current_task().condition_wait( lambda: self.__artistbrowse.is_loaded, 60 # Should be enough? )
def _add_missing_playlists(self): #Ensure that the container and loader length is the same self._fill_spaces(self.__container.num_playlists() - 1) #Iterate over the container to add the missing ones for pos, item in enumerate(self.__container.playlists()): #Check if we should continue current_task().check_status() if self.is_playlist(pos) and self.__playlists[pos] is None: self.add_playlist(item, pos)
def load_album_info(self, index, album): # Directly discard unavailable albums if not album.is_available(): self.__album_data[index] = { 'available_tracks': 0, 'type': self._get_album_type(album), } # Otherwise load its data else: cb = AlbumCallbacks(current_task()) album_info = albumbrowse.Albumbrowse(self.__session, album, cb) # Now wait until it's loaded self._wait_for_album_info(album_info) # Populate its data self.__album_data[index] = { 'available_tracks': self._num_available_tracks(album_info), 'type': self._get_album_type(album), } # Tell that we're done self.check()
def load_in_background(self): #Avoid entering this loop multiple times if self.__loader_lock.acquire(False): try: #Set the current task object self.__loader_task = current_task() #Reset everyting self._set_changes(False) self._set_error(False) #And call the method that does the actual loading task self._load() except: #Set the playlist's error flag self._set_error(True) finally: #Release and clear everything self.__loader_task = None self.__loader_lock.release() #If changes or errors were detected... if self.has_changes() or self.has_errors(): self.end_loading()
def _set_tracks(self, track_list, session, omit_offset): #Set the reference to the loop task self.__loop_task = current_task() #Clear playlist if no offset is given to omit if omit_offset is None: self.clear() #Iterate over the rest of the playlist for list_index, track in enumerate(track_list): #Check if we should continue self.__loop_task.check_status() #Don't add unplayable items to the playlist if self._item_is_playable(session, track): #Ignore the item at offset, which is already added if list_index != omit_offset: self._add_item(list_index, track, session) #Deal with any potential dummy items if omit_offset is not None and list_index < omit_offset: self.__playlist.remove('dummy-{0:d}'.format(list_index)) #Set paylist's shuffle status if self.get_shuffle_status(): self.__playlist.shuffle() #Clear the reference to the task self.__loop_task = None
def load_album_info(self, index, album): #Directly discard unavailable albums if not album.is_available(): self.__album_data[index] = { 'available_tracks': 0, 'type': self._get_album_type(album), } #Otherwise load it's data else: cb = AlbumCallbacks(current_task()) album_info = albumbrowse.Albumbrowse(self.__session, album, cb) #Now wait until it's loaded self._wait_for_album_info(album_info) #Populate it's data self.__album_data[index] = { 'available_tracks': self._num_available_tracks(album_info), 'type': self._get_album_type(album), } #Tell that we've done self.check()
def _set_tracks(self, track_list, session, omit_offset): # Set the reference to the loop task self.__loop_task = current_task() # Clear playlist if no offset is given to omit if omit_offset is None: self.clear() # Iterate over the rest of the playlist for list_index, track in enumerate(track_list): # Check if we should continue self.__loop_task.check_status() # Don't add unplayable items to the playlist if self._item_is_playable(session, track): # Ignore the item at offset, which is already added if list_index != omit_offset: self._add_item(list_index, track, session) # Deal with any potential dummy items if omit_offset is not None and list_index < omit_offset: self.__playlist.remove("dummy-{0:d}".format(list_index)) # Set paylist's shuffle status if self.get_shuffle_status(): self.__playlist.shuffle() # Clear the reference to the task self.__loop_task = None
def continue_in_background(self): #Set the reference to the current task self.__loader_task = current_task() #Wait until the album list got loaded self._wait_for_album_list() #Now load albumbrowse data from each one for index, album in enumerate(self.__artistbrowse.albums()): #Add a condition for the next wait self._add_album_processed_check(index) #Start loading the info in the background self.load_album_info(index, album) #Now wait until all info gets loaded current_task().condition_wait(self.__condition_list, 60) #Final steps... self.__is_loaded = True xbmc.executebuiltin("Action(Noop)")
def continue_in_background(self): # Set the reference to the current task self.__loader_task = current_task() # Wait until the album list got loaded self._wait_for_album_list() # Now load albumbrowse data from each one for index, album in enumerate(self.__artistbrowse.albums()): # Add a condition for the next wait self._add_album_processed_check(index) # Start loading the info in the background self.load_album_info(index, album) # Now wait until all info gets loaded current_task().condition_wait(self.__condition_list, 60) # Final steps... self.__is_loaded = True xbmc.executebuiltin("Action(Noop)")
def load_in_background(self): #Avoid entering here multiple times if self.__loader_lock.acquire(False): try: #Set the current task object self.__loader_task = current_task() #And take care of the rest self._load_container() finally: #Release and clear everything self.__loader_task = None self.__loader_lock.release()
def _wait_for_album_info(self, album_info): def info_is_loaded(): return album_info.is_loaded() if not info_is_loaded(): current_task().condition_wait(info_is_loaded, 10)
def _wait_for_conditions(self, timeout): current_task().condition_wait(self.__conditions, timeout)