diff --git a/ordigi/collection.py b/ordigi/collection.py index ddb853b..1608f94 100644 --- a/ordigi/collection.py +++ b/ordigi/collection.py @@ -760,6 +760,7 @@ class Collection(SortMedias): self.paths, root, self.opt['Exif'], + {}, self.db, self.opt['Terminal']['interactive'], ) @@ -876,12 +877,12 @@ class Collection(SortMedias): db_rows = [row['FilePath'] for row in self.db.sqlite.get_rows('metadata')] for file_path in file_paths: result = self.file_in_db(file_path, db_rows) - checksum = utils.checksum(file_path) + self.medias.checksums[file_path] = utils.checksum(file_path) if not result: self.log.error('Db data is not accurate') self.log.info(f'{file_path} not in db') return False - elif not self._check_file(file_path, checksum): + elif not self._check_file(file_path, self.medias.checksums[file_path]): # We d'ont want to silently ignore or correct this without # resetting the cache as is could be due to file corruption self.log.error(f'modified or corrupted file.') @@ -949,12 +950,13 @@ class Collection(SortMedias): relpath = os.path.relpath(file_path, self.root) metadata = {} - checksum = utils.checksum(file_path) - if not self._check_file(file_path, checksum) and update_checksum: + self.medias.checksums[file_path] = utils.checksum(file_path) + if ( + not self._check_file(file_path, self.medias.checksums[file_path]) + and update_checksum + ): # metatata will fill checksum from file - metadata = self.medias.get_metadata( - file_path, self.root, checksum, loc=loc - ) + metadata = self.medias.get_metadata(file_path, self.root, loc=loc) metadata['file_path'] = relpath # set row attribute to the file self.db.add_file_data(metadata) diff --git a/ordigi/media.py b/ordigi/media.py index 9860a3e..fb5a8a6 100644 --- a/ordigi/media.py +++ b/ordigi/media.py @@ -646,6 +646,7 @@ class Medias: paths, root, exif_options, + checksums=None, db=None, interactive=False, ): @@ -658,6 +659,11 @@ class Medias: self.root = root # Options + if checksums: + self.checksums = checksums + else: + self.checksums = {} + self.exif_opt = exif_options self.ignore_tags = self.exif_opt['ignore_tags'] @@ -684,7 +690,14 @@ class Medias: return media - def get_media_data(self, file_path, src_dir, checksum=None, loc=None): + def get_media_data(self, file_path, src_dir, loc=None): + """Get media class instance with metadata""" + + if self.checksums and file_path in self.checksums.keys(): + checksum = self.checksums[file_path] + else: + checksum = None + media = self.get_media(file_path, src_dir, checksum) media.get_metadata( self.root, loc, self.db.sqlite, self.exif_opt['cache'] @@ -692,9 +705,9 @@ class Medias: return media - def get_metadata(self, src_path, src_dir, checksum=None, loc=None): + def get_metadata(self, src_path, src_dir, loc=None): """Get metadata""" - return self.get_media_data(src_path, src_dir, checksum, loc).metadata + return self.get_media_data(src_path, src_dir, loc).metadata def get_paths(self, src_dirs, imp=False): """Get paths"""