diff --git a/phototrie/datename.py b/phototrie/datename.py index 89b1457..cded8ed 100644 --- a/phototrie/datename.py +++ b/phototrie/datename.py @@ -4,6 +4,8 @@ import sys import exifread import re +from exifread.classes import IfdTag + DATETIME_KEY = "Image DateTime" 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: if suffix == 0: - target = ( - f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}.{extension}" - ) + target = f"{dirn}/{year}-{month}-{date}_{hour}:{second}:{minute}{extension}" 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): return target @@ -59,7 +59,8 @@ def cli(): print(f"No datetime tag found for: {filename}", file=sys.stderr) 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: print( f"Invalid datetime tag ({tags[DATETIME_KEY]!r}) found for: {filename}",