def remove(self, book: Book): """ Remove all tracks of the given book from the cache. """ self._stop_processing() ids = {t.file_id for t in book.chapters} offline_elements = OfflineCacheModel.select().join(File).where( OfflineCacheModel.original_file.id << ids) for element in offline_elements: file_path = os.path.join(self.cache_dir, element.cached_file) if file_path == self.cache_dir: continue file = Gio.File.new_for_path(file_path) if file.query_exists(): file.delete() for item in self.queue: if self.current and item.id == self.current.id: self.filecopy_cancel.cancel() entries_to_delete = OfflineCacheModel.select().join(File).where( OfflineCacheModel.original_file.id << ids) ids_to_delete = [t.id for t in entries_to_delete] OfflineCacheModel.delete().where( OfflineCacheModel.id << ids_to_delete).execute() book.downloaded = False self.emit_event("book-offline-removed", book) self.queue = [] self._start_processing()
def remove(self, book): """ Remove all tracks of the given book from the cache. """ # self._stop_processing() tracks = get_tracks(book) ids = [t.id for t in tracks] offline_elements = OfflineCacheModel.select().where( OfflineCacheModel.track << ids) for element in offline_elements: file_path = os.path.join(self.cache_dir, element.file) if file_path == self.cache_dir: continue file = Gio.File.new_for_path(file_path) if file.query_exists(): file.delete() for item in self.queue: if self.current and item.id == self.current.id: self.filecopy_cancel.cancel() OfflineCacheModel.delete().where( OfflineCacheModel.track in ids).execute() if len(self.queue) > 0: self._start_processing()
def remove_all_for_storage(self, storage_path): """ """ for element in OfflineCacheModel.select().join(Track).where(storage_path in Track.file): file_path = os.path.join(self.cache_dir, element.file) if file_path == self.cache_dir: continue file = Gio.File.new_for_path(file_path) if file.query_exists(): file.delete() if element.track.book.offline == True: element.track.book.update(offline=False, downloaded=False).execute() OfflineCacheModel.delete().where(storage_path in OfflineCacheModel.track.file).execute()