def sort_file(self, path: Path): self.logger.info(f"Processing FILE {path}") path = self.cleanup_filename(path) incoming_image = ImageLoader.load(path) existing_image = self.find_existing(incoming_image.hash) if not existing_image: self.move_to_sorted(incoming_image) else: self.logger.info( f"Found match for incoming image {incoming_image}") self.logger.info(f" With existing image {existing_image}") self.keep_better(existing_image, incoming_image)
def reload(self, path: Path): self.logger.info(f"Reloading {path}") reloaded = ImageLoader.load(path) existing = self.db.get_by_hash(reloaded.hash) if existing and existing.path != path: self.logger.warning(f"Reloaded image: {reloaded}") self.logger.warning(f" Matches existing: {existing}") better = self.find_better(reloaded, existing) if better == reloaded: self.db.remove(existing) self.recycle(existing) else: self.db.remove(reloaded) self.recycle(reloaded) self.db.add(reloaded)
def keep_incoming(self, existing_image: ImageInfo, incoming_image: ImageInfo): self.logger.info(f"Deleting existing: {existing_image}") self.logger.info(f" Keeping incoming: {incoming_image}") if existing_image.path.name.lower().endswith( ".jpg" ) and existing_image.ts > OLD_TS and existing_image.ts < incoming_image.ts: self.logger.info( f" But preserving existing's exif: {existing_image}") try: piexif.transplant(existing_image.path.as_posix(), incoming_image.path.as_posix()) except ValueError as e: self.logger.warning(f"Failed to transplant exif: {e}") incoming_image = ImageLoader.load(incoming_image.path) self.db.remove(existing_image) self.recycle(existing_image) self.move_to_sorted(incoming_image)
def load_from_file(self, filename): """ Carrega os dados de um arquivo usando o loader strategy designado """ loader = ImageLoader() loader.load(self, filename)