Bugfix to datename

This commit is contained in:
Olivier 'reivilibre' 2021-04-08 14:08:04 +01:00
parent faa68a5d9f
commit 8a8e7b04a1
1 changed files with 6 additions and 5 deletions

View File

@ -4,6 +4,8 @@ import sys
import exifread import exifread
import re import re
from exifread.classes import IfdTag
DATETIME_KEY = "Image DateTime" DATETIME_KEY = "Image DateTime"
DATETIME_PATTERN = re.compile(r"^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$") DATETIME_PATTERN = re.compile(r"^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$")
@ -18,11 +20,9 @@ def get_new_name(filename, date_matches):
while True: while True:
if suffix == 0: if suffix == 0:
target = ( target = f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}{extension}"
f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}.{extension}"
)
else: else:
target = f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}_{suffix}.{extension}" target = f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}_{suffix}{extension}"
if not os.path.exists(target): if not os.path.exists(target):
return target return target
@ -59,7 +59,8 @@ def cli():
print(f"No datetime tag found for: {filename}", file=sys.stderr) print(f"No datetime tag found for: {filename}", file=sys.stderr)
continue continue
match = DATETIME_PATTERN.match(tags[DATETIME_KEY]) ifd_tag: IfdTag = tags[DATETIME_KEY]
match = DATETIME_PATTERN.match(ifd_tag.values)
if match is None: if match is None:
print( print(
f"Invalid datetime tag ({tags[DATETIME_KEY]!r}) found for: {filename}", f"Invalid datetime tag ({tags[DATETIME_KEY]!r}) found for: {filename}",