Beispiel #1
0
 def __on_get_similar_artists(self, artists):
     """
         Add artist to view
         @param artists as [(str, str)]
     """
     if artists:
         self.__stack.set_visible_child(self.__listbox)
         self.__label.hide()
         (artist, cover_uri) = artists.pop(0)
         if artist in self.__added:
             GLib.idle_add(self.__on_get_similar_artists, artists)
             return
         self.__added.append(artist)
         artist_id = App().artists.get_id_for_escaped_string(
             sql_escape(artist))
         row = None
         if artist_id is not None and App().artists.has_albums(artist_id):
             # We want real artist name (with case)
             artist = App().artists.get_name(artist_id)
             row = ArtistRow(artist, None, self.__cancellable,
                             StorageType.COLLECTION)
         if row is None and self.__show_all:
             row = ArtistRow(artist, cover_uri, self.__cancellable,
                             StorageType.EPHEMERAL)
         if row is not None:
             row.show()
             self.__listbox.add(row)
         GLib.idle_add(self.__on_get_similar_artists, artists)
     else:
         self.__label.set_text(_("No results"))
Beispiel #2
0
 def _on_match_album(self, search, album_id, storage_type):
     """
         Add a new album to view
         @param search as *Search
         @param artist_id as int
         @param storage_type as StorageType
     """
     if storage_type & StorageType.SEARCH:
         artist_match = False
         album = Album(album_id)
         if album.artists:
             artist = sql_escape(album.artists[0])
             search = sql_escape(self.__current_search)
             artist_match = artist.find(search) != -1
         if artist_match:
             self._on_match_artist(search, album.artist_ids[0],
                                   storage_type)
         else:
             self.__stack.current_child.albums_line_view.show()
             self.__stack.current_child.albums_line_view.add_value(album)
             self.show_placeholder(False)
 def __get_artist_ids(self, artists):
     """
         Get valid artist ids from list
         @param artists as []
         @return [int]
     """
     similar_artist_ids = []
     for (artist, cover_uri) in artists:
         similar_artist_id = App().artists.get_id_for_escaped_string(
             sql_escape(artist.lower()))
         if similar_artist_id is not None:
             if App().artists.has_albums(similar_artist_id):
                 similar_artist_ids.append(similar_artist_id)
     return similar_artist_ids
Beispiel #4
0
 def get_id(self, name):
     """
         Get genre id for name
         @param name as string
         @return genre id as int
     """
     with SqlCursor(self.__db) as sql:
         # Escape string to fix mixed tags:
         # Alternative Rock, Aternative-Rock, alternative rock
         result = sql.execute("SELECT rowid FROM genres\
                               WHERE sql_escape(name)=?",
                              (sql_escape(name),))
         v = result.fetchone()
         if v is not None:
             return v[0]
         return None
Beispiel #5
0
 def __on_row_activated(self, widget, row):
     """
         Play searched item when selected
         @param widget as Gtk.ListBox
         @param row as Gtk.ListBoxRow
     """
     # Close popover
     popover = self.get_ancestor(Gtk.Popover)
     if popover is not None:
         popover.hide()
     artist_name = row.artist_name
     if row.storage_type == StorageType.EPHEMERAL:
         App().lookup_action("search").activate(
             GLib.Variant("s", artist_name))
     else:
         artist_id = App().artists.get_id_for_escaped_string(
             sql_escape(artist_name))
         App().window.container.show_view([Type.ARTISTS], [artist_id])