def save_album( self, item, ): """ Add album to DB @param item as CollectionItem """ Logger.debug("CollectionScanner::save_album(): " "Add album artists %s" % item.album_artists) (item.new_album_artist_ids, item.album_artist_ids) = self.add_artists(item.album_artists, item.aa_sortnames, item.mb_album_artist_id) # We handle artists already created by any previous save_track() for artist_id in item.album_artist_ids: if artist_id in self.__pending_new_artist_ids: item.new_album_artist_ids.append(artist_id) self.__pending_new_artist_ids.remove(artist_id) item.lp_album_id = get_lollypop_album_id(item.album_name, item.album_artists) Logger.debug("CollectionScanner::save_track(): Add album: " "%s, %s" % (item.album_name, item.album_artist_ids)) (item.new_album, item.album_id) = self.add_album( item.album_name, item.mb_album_id, item.lp_album_id, item.album_artist_ids, item.uri, item.album_loved, item.album_pop, item.album_rate, item.album_synced, item.album_mtime, item.storage_type) if item.year is not None: App().albums.set_year(item.album_id, item.year) App().albums.set_timestamp(item.album_id, item.timestamp)
def do_migration(dialog, label, progress): GLib.idle_add(label.set_text, _("Please wait while Lollypop is updating albums")) album_ids = albums.get_ids([], [], StorageType.ALL, True) album_ids += albums.get_compilation_ids([], StorageType.ALL, True) count = len(album_ids) i = 0 for album_id in album_ids: if i % 10 == 0: GLib.idle_add(progress.set_fraction, i / count) name = albums.get_name(album_id) artists = ";".join(albums.get_artists(album_id)) lp_album_id = get_lollypop_album_id(name, artists) albums.set_lp_album_id(album_id, lp_album_id) i += 1 track_ids = tracks.get_ids(StorageType.ALL, True) count = len(track_ids) i = 0 GLib.idle_add(label.set_text, _("Please wait while Lollypop is updating tracks")) for track_id in track_ids: if i % 10 == 0: GLib.idle_add(progress.set_fraction, i / count) name = tracks.get_name(track_id) artists = ";".join(tracks.get_artists(track_id)) album_name = tracks.get_album_name(track_id) lp_track_id = get_lollypop_track_id(name, artists, album_name) tracks.set_lp_track_id(track_id, lp_track_id) i += 1 GLib.idle_add(dialog.destroy)
def save_album_payload_to_db(self, payload, storage_type, notify, cancellable): """ Save album to DB @param payload as {} @param storage_type as StorageType @param notify as bool @param cancellable as Gio.Cancellable @return CollectionItem/None """ lp_album_id = get_lollypop_album_id(payload["name"], payload["artists"]) album_id = App().albums.get_id_for_lp_album_id(lp_album_id) if album_id >= 0: album = Album(album_id) if notify: emit_signal(self, "match-album", album_id, storage_type) return album.collection_item item = self.__save_album(payload, storage_type) album = Album(item.album_id) if notify: self.save_artwork(album, payload["artwork-uri"], cancellable) emit_signal(self, "match-album", album.id, storage_type) return item
def update_album(self, item): """ Update album artists based on album-artist and artist tags This code auto handle compilations: empty "album artist" with different artists @param item as CollectionItem """ if item.album_artist_ids: App().albums.set_artist_ids(item.album_id, item.album_artist_ids) # Set artist ids based on content else: if item.compilation: new_album_artist_ids = [Type.COMPILATIONS] else: new_album_artist_ids = App().albums.calculate_artist_ids( item.album_id, self.__disable_compilations) App().albums.set_artist_ids(item.album_id, new_album_artist_ids) # We handle artists already created by any previous save_track() item.new_album_artist_ids = [] for artist_id in new_album_artist_ids: if artist_id in self.__pending_new_artist_ids: item.new_album_artist_ids.append(artist_id) self.__pending_new_artist_ids.remove(artist_id) # Update lp_album_id lp_album_id = get_lollypop_album_id(item.album_name, item.album_artists) if lp_album_id != item.lp_album_id: App().art.move_artwork(item.lp_album_id, lp_album_id) App().albums.set_lp_album_id(item.album_id, lp_album_id) item.lp_album_id = lp_album_id # Update album genres for genre_id in item.genre_ids: App().albums.add_genre(item.album_id, genre_id) # Update year based on tracks year = App().tracks.get_year_for_album(item.album_id) if year is not None: App().albums.set_year(item.album_id, year) timestamp = App().tracks.get_timestamp_for_album(item.album_id) App().albums.set_timestamp(item.album_id, timestamp) App().cache.clear_durations(item.album_id)