Add fill date original option

This commit is contained in:
Cédric Leporcq 2022-04-23 18:39:13 +02:00
parent fd35963994
commit 503b90b631
5 changed files with 27 additions and 12 deletions

View File

@ -70,10 +70,18 @@ _filter_options = [
_sort_options = [
click.option(
'--album-from-folder',
'-a',
default=False,
is_flag=True,
help="Use images' folders as their album names.",
),
click.option(
'--fill-date-original',
'-O',
default=False,
is_flag=True,
help="Fill date original from date media if not set",
),
click.option(
'--path-format',
'-p',
@ -550,6 +558,7 @@ def _sort(**kwargs):
{
'album_from_folder': kwargs['album_from_folder'],
'cache': cache,
'fill_date_original': kwargs['fill_date_original'],
'ignore_tags': kwargs['ignore_tags'],
'use_date_filename': kwargs['use_date_filename'],
'use_file_dates': kwargs['use_file_dates'],

View File

@ -524,7 +524,6 @@ class SortMedias:
checksum = utils.checksum(dest_path)
metadata['checksum'] = checksum
if not self.dry_run:
self.db.add_file_data(metadata)
if imp != 'copy' and self.root in src_path.parents:
self.db.sqlite.delete_filepath(str(src_path.relative_to(self.root)))

View File

@ -60,6 +60,7 @@ class Config:
return {
'Exif': {
'album_from_folder': False,
'fill_date_original': False,
'cache': True,
'ignore_tags': None,
'use_date_filename': False,
@ -130,11 +131,12 @@ class Config:
def get_config_option(self, section, option):
bool_options = {
'album_from_folder',
'fill_date_original',
'cache',
'dry_run',
'prefer_english_names',
'album_from_folder',
'interactive',
'prefer_english_names',
'use_date_filename',
'use_file_dates',
}

View File

@ -674,7 +674,7 @@ class Medias:
# Options
self.exif_opt = exif_options
self.album_from_folder = self.exif_opt['album_from_folder']
self.ignore_tags = self.exif_opt['ignore_tags']
self.interactive = interactive
self.log = LOG.getChild(self.__class__.__name__)
@ -688,8 +688,8 @@ class Medias:
media = Media(
file_path,
src_dir,
self.album_from_folder,
self.ignore_tags,
self.exif_opt['album_from_folder'],
self.exif_opt['ignore_tags'],
self.interactive,
self.exif_opt['cache'],
self.exif_opt['use_date_filename'],
@ -748,21 +748,25 @@ class Medias:
exif = WriteExif(
file_path,
metadata,
ignore_tags=self.ignore_tags,
ignore_tags=self.exif_opt['ignore_tags'],
)
updated = False
if self.album_from_folder:
exif.set_album_from_folder()
updated = True
if metadata['original_name'] in (False, ''):
if metadata['original_name'] in (None, ''):
exif.set_value('original_name', metadata['filename'])
updated = True
if self.album_from_folder:
if self.exif_opt['album_from_folder']:
exif.set_album_from_folder()
album = metadata['album']
if album and album != '':
exif.set_value('album', album)
updated = True
if (
self.exif_opt['fill_date_original']
and metadata['date_original'] in (None, '')
):
exif.set_key_values('date_original', metadata['date_media'])
updated = True
if updated:
return True

View File

@ -34,6 +34,7 @@ class TestOrdigi:
)
cls.sort_options = (
'--album-from-folder',
'--fill-date-original',
'--path-format',
'--remove-duplicates',
'--use-date-filename',