def __load_pixbuf_from_cache(book, size): """ """ pixbuf = None query = cozy.db.ArtworkCache.select().where(cozy.db.ArtworkCache.book == book.id) if query.exists(): uuid = query.first().uuid else: return None cache_dir = os.path.join(tools.get_cache_dir(), "artwork") cache_dir = os.path.join(cache_dir, uuid) try: if os.path.exists(cache_dir): file_path = os.path.join(cache_dir, str(size) + ".jpg") if os.path.exists(file_path): pixbuf = GdkPixbuf.Pixbuf.new_from_file(os.path.join(cache_dir, str(size) + ".jpg")) else: return None except Exception as e: log.warning(e) return None return pixbuf
def __create_artwork_cache(book, pixbuf, size): """ Creates a resized cache version of the given pixbuf and saves it in the cozy cache folder under a unique identifier. :param book: Book which the artwork is from :param pixbuf: Pixbuf to be cached :param size: Size for the cached version :return: Resized pixbuf """ query = cozy.db.ArtworkCache.select().where(cozy.db.ArtworkCache.book == book.id) gen_uuid = "" if query.exists(): gen_uuid = str(query.first().uuid) else: gen_uuid = str(uuid.uuid4()) cozy.db.ArtworkCache.create(book = book, uuid=gen_uuid) cache_dir = os.path.join(os.path.join(tools.get_cache_dir(), "artwork"), gen_uuid) if not os.path.exists(cache_dir): os.makedirs(cache_dir) resized_pixbuf = __resize_pixbuf(pixbuf, size) file_path = os.path.join(cache_dir, str(size) + ".jpg") if not os.path.exists(file_path): try: resized_pixbuf.savev(file_path, "jpeg", ["quality", None], ["95"]) except Exception as e: log.warning("Failed to save resized cache albumart for following uuid: " + gen_uuid) log.warning(e) return resized_pixbuf
def delete_cache(self): """ Deletes the entire offline cache files. Doesn't delete anything from the cozy.db. """ cache_dir = os.path.join(tools.get_cache_dir(), "offline") import shutil shutil.rmtree(cache_dir)
def __init__(self): self.ui = cozy.ui.main_view.CozyUI() self.cache_dir = os.path.join(tools.get_cache_dir(), "offline") if not os.path.exists(self.cache_dir): os.makedirs(self.cache_dir) self._start_processing() cozy.ui.settings.Settings().add_listener(self.__on_settings_changed)
def delete_artwork_cache(): """ Deletes the artwork cache completely. """ cache_dir = tools.get_cache_dir() import shutil shutil.rmtree(cache_dir) q = ArtworkCache.delete() q.execute()
def delete_artwork_cache(): """ Deletes the artwork cache completely. """ cache_dir = os.path.join(tools.get_cache_dir(), "artwork") import shutil if os.path.exists(cache_dir): shutil.rmtree(cache_dir) q = cozy.db.ArtworkCache.delete() q.execute()
def __load_artwork_placeholder(size): """ Loads the artwork placeholder first from cache and then from file. Creates cached versions if it doesn't exist already at the given size. :param size: Size in px for the placeholder :return: Placeholder pixbuf at given size """ pixbuf = None file_path = os.path.join(tools.get_cache_dir(), "placeholder_" + str(size) + ".jpg") if os.path.exists(file_path): pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_path) else: pixbuf = GdkPixbuf.Pixbuf.new_from_resource("/de/geigi/cozy/blank_album.png") pixbuf = __resize_pixbuf(pixbuf, size) pixbuf.save(file_path, "jpeg") return pixbuf
def update_db_6(): """ Update database to v6. """ migrator = SqliteMigrator(db) db.create_tables([OfflineCache]) external = BooleanField(default=False) offline = BooleanField(default=False) downloaded = BooleanField(default=False) migrate(migrator.add_column('storage', 'external', external), migrator.add_column('book', 'offline', offline), migrator.add_column('book', 'downloaded', downloaded)) Settings.update(version=6).execute() import shutil shutil.rmtree(tools.get_cache_dir())