def save_album_artwork(self, data, album_id): """ Save data for album id @param data as bytes @param album id as int """ try: album = Album(album_id) path_count = Lp().albums.get_path_count(album.path) filename = self._get_album_cache_name(album) + ".jpg" # Many albums with same path, suffix with artist_album name if path_count > 1: artpath = os.path.join(album.path, filename) if os.path.exists(os.path.join(album.path, self._favorite)): os.remove(os.path.join(album.path, self._favorite)) elif is_readonly(album.path): artpath = os.path.join(self._STORE_PATH, filename) else: artpath = os.path.join(album.path, self._favorite) stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None) pixbuf.savev(artpath, "jpeg", ["quality"], ["90"]) del pixbuf except Exception as e: print("Art::save_album_artwork(): %s" % e)
def save_album_artwork(self, data, album_id): """ Save data for album id @param data as bytes @param album id as int """ try: album = Album(album_id) arturi = None save_to_tags = Lp().settings.get_value("save-to-tags") and\ not album.is_web uri_count = Lp().albums.get_uri_count(album.uri) filename = self.get_album_cache_name(album) + ".jpg" if save_to_tags: t = Thread(target=self.__save_artwork_tags, args=(data, album)) t.daemon = True t.start() store_path = self._STORE_PATH + "/" + filename if album.uri == "" or is_readonly(album.uri): arturi = GLib.filename_to_uri(store_path) # Many albums with same path, suffix with artist_album name elif uri_count > 1: arturi = album.uri + "/" + filename favorite_uri = album.uri + "/" + self.__favorite favorite = Lio.File.new_for_uri(favorite_uri) if favorite.query_exists(): favorite.trash() else: arturi = album.uri + "/" + self.__favorite # Save cover to uri if not save_to_tags: stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None) stream.close() pixbuf.savev(store_path, "jpeg", ["quality"], [str(Lp().settings.get_value( "cover-quality").get_int32())]) dst = Lio.File.new_for_uri(arturi) src = Lio.File.new_for_path(store_path) src.move(dst, Gio.FileCopyFlags.OVERWRITE, None, None) del pixbuf self.clean_album_cache(album) GLib.idle_add(self.album_artwork_update, album.id) else: dst = Lio.File.new_for_uri(arturi) if dst.query_exists(): dst.trash() except Exception as e: print("Art::save_album_artwork(): %s" % e)
def save_album_artwork(self, data, album_id): """ Save data for album id @param data as bytes @param album id as int """ try: artpath = None save_to_tags = Lp().settings.get_value('artwork-tags') and\ which("kid3-cli") is not None album = Album(album_id) path_count = Lp().albums.get_path_count(album.path) filename = self._get_album_cache_name(album) + ".jpg" if save_to_tags: t = Thread(target=self._save_artwork_tags, args=(data, album)) t.daemon = True t.start() # Many albums with same path, suffix with artist_album name if path_count > 1: artpath = os.path.join(album.path, filename) if os.path.exists(os.path.join(album.path, self._favorite)): os.remove(os.path.join(album.path, self._favorite)) elif is_readonly(album.path): artpath = os.path.join(self._STORE_PATH, filename) else: artpath = os.path.join(album.path, self._favorite) # Update cover file if exists event if we have written to tags if not save_to_tags or os.path.exists(artpath): stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None) pixbuf.savev(artpath, "jpeg", ["quality"], ["90"]) del pixbuf self.clean_album_cache(album) GLib.idle_add(self.album_artwork_update, album.id) except Exception as e: print("Art::save_album_artwork(): %s" % e)
def save_album_artwork(self, data, album_id): """ Save data for album id @param data as bytes @param album id as int """ try: artpath = None save_to_tags = Lp().settings.get_value('save-to-tags') and\ which("kid3-cli") is not None album = Album(album_id) path_count = Lp().albums.get_path_count(album.path) filename = self.get_album_cache_name(album) + ".jpg" if save_to_tags: t = Thread(target=self.__save_artwork_tags, args=(data, album)) t.daemon = True t.start() if album.path == "" or is_readonly(album.path): artpath = os.path.join(self._STORE_PATH, filename) # Many albums with same path, suffix with artist_album name elif path_count > 1: artpath = os.path.join(album.path, filename) if os.path.exists(os.path.join(album.path, self.__favorite)): os.remove(os.path.join(album.path, self.__favorite)) else: artpath = os.path.join(album.path, self.__favorite) # Update cover file if exists event if we have written to tags if not save_to_tags or os.path.exists(artpath): stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None) pixbuf.savev(artpath, "jpeg", ["quality"], ["90"]) del pixbuf self.clean_album_cache(album) GLib.idle_add(self.album_artwork_update, album.id) except Exception as e: print("Art::save_album_artwork(): %s" % e)
def save_album_artwork(self, data, album_id): """ Save data for album id @param data as bytes @param album id as int """ try: album = Album(album_id) arturi = None # Check portal for kid3-cli can_set_cover = False try: bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) proxy = Gio.DBusProxy.new_sync( bus, Gio.DBusProxyFlags.NONE, None, 'org.gnome.Lollypop.Portal', '/org/gnome/LollypopPortal', 'org.gnome.Lollypop.Portal', None) can_set_cover = proxy.call_sync( 'CanSetCover', None, Gio.DBusCallFlags.NO_AUTO_START, 500, None)[0] except: print("You are missing lollypop-portal: " "https://github.com/gnumdk/lollypop-portal") save_to_tags = Lp().settings.get_value('save-to-tags') and\ can_set_cover and not album.is_web uri_count = Lp().albums.get_uri_count(album.uri) filename = self.get_album_cache_name(album) + ".jpg" if save_to_tags: t = Thread(target=self.__save_artwork_tags, args=(data, album)) t.daemon = True t.start() store_path = self._STORE_PATH + "/" + filename if album.uri == "" or is_readonly(album.uri): arturi = GLib.filename_to_uri(store_path) # Many albums with same path, suffix with artist_album name elif uri_count > 1: arturi = album.uri + "/" + filename favorite_uri = album.uri + "/" + self.__favorite favorite = Lio.File.new_for_uri(favorite_uri) if favorite.query_exists(): favorite.trash() else: arturi = album.uri + "/" + self.__favorite f = Lio.File.new_for_uri(arturi) # Update cover file if exists even if we have written to tags if not save_to_tags or f.query_exists(): stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None) stream.close() pixbuf.savev(store_path, "jpeg", ["quality"], [str(Lp().settings.get_value( 'cover-quality').get_int32())]) dst = Lio.File.new_for_uri(arturi) src = Lio.File.new_for_path(store_path) src.move(dst, Gio.FileCopyFlags.OVERWRITE, None, None) del pixbuf self.clean_album_cache(album) GLib.idle_add(self.album_artwork_update, album.id) except Exception as e: print("Art::save_album_artwork(): %s" % e)
def save_album_artwork(self, data, album_id): """ Save data for album id @param data as bytes @param album id as int """ try: arturi = None # Check portal for kid3-cli can_set_cover = False try: bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) proxy = Gio.DBusProxy.new_sync( bus, Gio.DBusProxyFlags.NONE, None, 'org.gnome.Lollypop.Portal', '/org/gnome/LollypopPortal', 'org.gnome.Lollypop.Portal', None) can_set_cover = proxy.call_sync( 'CanSetCover', None, Gio.DBusCallFlags.NO_AUTO_START, 500, None)[0] except Exception as e: print("SettingsDialog::__init__():", e) save_to_tags = Lp().settings.get_value('save-to-tags') and\ can_set_cover album = Album(album_id) uri_count = Lp().albums.get_uri_count(album.uri) filename = self.get_album_cache_name(album) + ".jpg" if save_to_tags: t = Thread(target=self.__save_artwork_tags, args=(data, album)) t.daemon = True t.start() store_path = self._STORE_PATH + "/" + filename if album.uri == "" or is_readonly(album.uri): arturi = GLib.filename_to_uri(store_path) # Many albums with same path, suffix with artist_album name elif uri_count > 1: arturi = album.uri + "/" + filename favorite_uri = album.uri + "/" + self.__favorite favorite = Gio.File.new_for_uri(favorite_uri) if favorite.query_exists(): favorite.trash() else: arturi = album.uri + "/" + self.__favorite f = Gio.File.new_for_uri(arturi) # Update cover file if exists even if we have written to tags if not save_to_tags or f.query_exists(): stream = Gio.MemoryInputStream.new_from_data(data, None) pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale( stream, ArtSize.MONSTER, ArtSize.MONSTER, True, None) pixbuf.savev(store_path, "jpeg", ["quality"], ["90"]) dst = Gio.File.new_for_uri(arturi) src = Gio.File.new_for_path(store_path) src.move(dst, Gio.FileCopyFlags.OVERWRITE, None, None) del pixbuf self.clean_album_cache(album) GLib.idle_add(self.album_artwork_update, album.id) except Exception as e: print("Art::save_album_artwork(): %s" % e)