Let read_mtime overwrite the name even if already formatted.

This commit is contained in:
voussoir 2026-07-26 15:00:46 -07:00
parent ad072fb39b
commit aef467dfdd

View file

@ -21,8 +21,9 @@ def makename(file, read_exif=False, read_mtime=False, minus_duration=False):
final_pattern = r'^(\d\d\d\d)-(\d\d)-(\d\d)_(\d\d)-(\d\d)-(\d\d)(?:x\d+)?$' final_pattern = r'^(\d\d\d\d)-(\d\d)-(\d\d)_(\d\d)-(\d\d)-(\d\d)(?:x\d+)?$'
# Already optimized filenames need not apply # Already optimized filenames need not apply
# This is also important when the filename and the exif disagree # This is also important when the filename and the exif disagree
if re.match(final_pattern, old) and not read_exif: if re.match(final_pattern, old) and not read_exif and not read_mtime:
return file # return file
pass
# Microsoft ICE # Microsoft ICE
new = re.sub( new = re.sub(
@ -156,9 +157,6 @@ def makename(file, read_exif=False, read_mtime=False, minus_duration=False):
if new == old and read_exif and file.extension in {'jpg', 'jpeg', 'dng'}: if new == old and read_exif and file.extension in {'jpg', 'jpeg', 'dng'}:
new = makename_exif(file, old) new = makename_exif(file, old)
if new == old and re.match(final_pattern, new):
return file
if new == old and read_mtime: if new == old and read_mtime:
mtime = file.stat.st_mtime mtime = file.stat.st_mtime
if minus_duration: if minus_duration:
@ -166,6 +164,9 @@ def makename(file, read_exif=False, read_mtime=False, minus_duration=False):
date = datetime.datetime.fromtimestamp(mtime) date = datetime.datetime.fromtimestamp(mtime)
new = date.strftime('%Y-%m-%d_%H-%M-%S') new = date.strftime('%Y-%m-%d_%H-%M-%S')
if new == old:
return file
new = file.parent.with_child(new).add_extension(file.extension) new = file.parent.with_child(new).add_extension(file.extension)
return new return new