def do(self, search_items): """ Return tracks containing name @param search items as [str] @return tracks as [SearchItem] """ self.__stop = False # Local search added_album_ids = [] added_track_ids = [] for item in search_items: if self.__stop: return albums = [] tracks_non_album_artist = [] # Get all albums for all artists and non album_artist tracks for artist_id in Lp().artists.search(item): if self.__stop: return for album_id in Lp().albums.get_ids([artist_id], []): if (album_id, artist_id) not in albums: albums.append((album_id, artist_id)) for track_id, track_name in Lp( ).tracks.get_as_non_album_artist(artist_id): tracks_non_album_artist.append((track_id, track_name)) for album_id, artist_id in albums: if self.__stop: return if album_id in added_album_ids: continue search_item = SearchItem() search_item.id = album_id added_album_ids.append(album_id) search_item.is_track = False search_item.artist_ids = [artist_id] self._items.append(search_item) GLib.idle_add(self.emit, 'item-found') albums = Lp().albums.search(item) for album_id in albums: if self.__stop: return if album_id in added_album_ids: continue search_item = SearchItem() search_item.id = album_id added_album_ids.append(album_id) search_item.is_track = False search_item.artist_ids = Lp().albums.get_artist_ids(album_id) self._items.append(search_item) GLib.idle_add(self.emit, 'item-found') for track_id, track_name in Lp().tracks.search( item) + tracks_non_album_artist: if self.__stop: return if track_id in added_track_ids: continue search_item = SearchItem() search_item.id = track_id added_track_ids.append(track_id) search_item.is_track = True search_item.artist_ids = Lp().tracks.get_artist_ids(track_id) self._items.append(search_item) GLib.idle_add(self.emit, 'item-found') self._finished = True GLib.idle_add(self.emit, 'item-found')
def __populate(self): """ Populate searching items in db based on text entry current text """ GLib.idle_add(self.__clear) # Network Search t = Thread(target=self.__network_search) t.daemon = True t.start() # Local search results = [] added_album_ids = [] added_track_ids = [] search_items = [self.__current_search] # search_items += self.__current_search.split() for item in search_items: albums = [] tracks_non_album_artist = [] # Get all albums for all artists and non album_artist tracks for artist_id in Lp().artists.search(item): for album_id in Lp().albums.get_ids([artist_id], []): if (album_id, artist_id) not in albums: albums.append((album_id, artist_id)) for track_id, track_name in Lp( ).tracks.get_as_non_album_artist(artist_id): tracks_non_album_artist.append((track_id, track_name)) for album_id, artist_id in albums: if album_id in added_album_ids: continue search_item = SearchItem() search_item.id = album_id added_album_ids.append(album_id) search_item.is_track = False search_item.artist_ids = [artist_id] results.append(search_item) albums = Lp().albums.search(item) for album_id in albums: if album_id in added_album_ids: continue search_item = SearchItem() search_item.id = album_id added_album_ids.append(album_id) search_item.is_track = False search_item.artist_ids = Lp().albums.get_artist_ids(album_id) results.append(search_item) for track_id, track_name in Lp().tracks.search( item) + tracks_non_album_artist: if track_id in added_track_ids: continue search_item = SearchItem() search_item.id = track_id added_track_ids.append(track_id) search_item.is_track = True search_item.artist_ids = Lp().tracks.get_artist_ids(track_id) results.append(search_item) if not self.__stop_thread: GLib.idle_add(self.__add_rows_internal, results) else: self.__in_thread = False self.__stop_thread = False if not self.__need_network_search(): self.__stack.set_visible_child(self.__new_btn) self.__spinner.stop()