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 = [ _sort_options = [
click.option( click.option(
'--album-from-folder', '--album-from-folder',
'-a',
default=False, default=False,
is_flag=True, is_flag=True,
help="Use images' folders as their album names.", 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( click.option(
'--path-format', '--path-format',
'-p', '-p',
@ -550,6 +558,7 @@ def _sort(**kwargs):
{ {
'album_from_folder': kwargs['album_from_folder'], 'album_from_folder': kwargs['album_from_folder'],
'cache': cache, 'cache': cache,
'fill_date_original': kwargs['fill_date_original'],
'ignore_tags': kwargs['ignore_tags'], 'ignore_tags': kwargs['ignore_tags'],
'use_date_filename': kwargs['use_date_filename'], 'use_date_filename': kwargs['use_date_filename'],
'use_file_dates': kwargs['use_file_dates'], 'use_file_dates': kwargs['use_file_dates'],

View File

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

View File

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

View File

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

View File

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