Add checksum dict
This commit is contained in:
parent
9e32052ce3
commit
47b9aa57ae
|
@ -760,6 +760,7 @@ class Collection(SortMedias):
|
||||||
self.paths,
|
self.paths,
|
||||||
root,
|
root,
|
||||||
self.opt['Exif'],
|
self.opt['Exif'],
|
||||||
|
{},
|
||||||
self.db,
|
self.db,
|
||||||
self.opt['Terminal']['interactive'],
|
self.opt['Terminal']['interactive'],
|
||||||
)
|
)
|
||||||
|
@ -876,12 +877,12 @@ class Collection(SortMedias):
|
||||||
db_rows = [row['FilePath'] for row in self.db.sqlite.get_rows('metadata')]
|
db_rows = [row['FilePath'] for row in self.db.sqlite.get_rows('metadata')]
|
||||||
for file_path in file_paths:
|
for file_path in file_paths:
|
||||||
result = self.file_in_db(file_path, db_rows)
|
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:
|
if not result:
|
||||||
self.log.error('Db data is not accurate')
|
self.log.error('Db data is not accurate')
|
||||||
self.log.info(f'{file_path} not in db')
|
self.log.info(f'{file_path} not in db')
|
||||||
return False
|
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
|
# We d'ont want to silently ignore or correct this without
|
||||||
# resetting the cache as is could be due to file corruption
|
# resetting the cache as is could be due to file corruption
|
||||||
self.log.error(f'modified or corrupted file.')
|
self.log.error(f'modified or corrupted file.')
|
||||||
|
@ -949,12 +950,13 @@ class Collection(SortMedias):
|
||||||
relpath = os.path.relpath(file_path, self.root)
|
relpath = os.path.relpath(file_path, self.root)
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
||||||
checksum = utils.checksum(file_path)
|
self.medias.checksums[file_path] = utils.checksum(file_path)
|
||||||
if not self._check_file(file_path, checksum) and update_checksum:
|
if (
|
||||||
|
not self._check_file(file_path, self.medias.checksums[file_path])
|
||||||
|
and update_checksum
|
||||||
|
):
|
||||||
# metatata will fill checksum from file
|
# metatata will fill checksum from file
|
||||||
metadata = self.medias.get_metadata(
|
metadata = self.medias.get_metadata(file_path, self.root, loc=loc)
|
||||||
file_path, self.root, checksum, loc=loc
|
|
||||||
)
|
|
||||||
metadata['file_path'] = relpath
|
metadata['file_path'] = relpath
|
||||||
# set row attribute to the file
|
# set row attribute to the file
|
||||||
self.db.add_file_data(metadata)
|
self.db.add_file_data(metadata)
|
||||||
|
|
|
@ -646,6 +646,7 @@ class Medias:
|
||||||
paths,
|
paths,
|
||||||
root,
|
root,
|
||||||
exif_options,
|
exif_options,
|
||||||
|
checksums=None,
|
||||||
db=None,
|
db=None,
|
||||||
interactive=False,
|
interactive=False,
|
||||||
):
|
):
|
||||||
|
@ -658,6 +659,11 @@ class Medias:
|
||||||
self.root = root
|
self.root = root
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
|
if checksums:
|
||||||
|
self.checksums = checksums
|
||||||
|
else:
|
||||||
|
self.checksums = {}
|
||||||
|
|
||||||
self.exif_opt = exif_options
|
self.exif_opt = exif_options
|
||||||
|
|
||||||
self.ignore_tags = self.exif_opt['ignore_tags']
|
self.ignore_tags = self.exif_opt['ignore_tags']
|
||||||
|
@ -684,7 +690,14 @@ class Medias:
|
||||||
|
|
||||||
return media
|
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 = self.get_media(file_path, src_dir, checksum)
|
||||||
media.get_metadata(
|
media.get_metadata(
|
||||||
self.root, loc, self.db.sqlite, self.exif_opt['cache']
|
self.root, loc, self.db.sqlite, self.exif_opt['cache']
|
||||||
|
@ -692,9 +705,9 @@ class Medias:
|
||||||
|
|
||||||
return media
|
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"""
|
"""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):
|
def get_paths(self, src_dirs, imp=False):
|
||||||
"""Get paths"""
|
"""Get paths"""
|
||||||
|
|
Loading…
Reference in New Issue