Use exiftool instead because it handles more filetypes

including MP4 (!!!)
master
parent df3e79b9e6
commit 556696f0f8
  1. 2
      README.md
  2. 17
      phototrie/datename.py
  3. 2
      setup.py

@ -39,6 +39,8 @@ with the same name will also be processed.
Once you are ready to apply the changes for real, pass `--apply` (or `-y`).
**datename requires `exiftool` to be installed.**
### batchrename
`batchrename <regex> <replacement> photo1.jpg photo2.jpg` (etc)

@ -1,12 +1,12 @@
import argparse
import os
import sys
import exifread
import re
from exifread.classes import IfdTag
from exiftool import ExifTool
DATETIME_KEY = "Image DateTime"
DATETIME_KEY = "EXIF:CreateDate"
DATETIME_PATTERN = re.compile(r"^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})$")
@ -55,16 +55,19 @@ def cli():
args = parser.parse_args(sys.argv[1:])
exifreader = ExifTool()
exifreader.start()
for filename in args.files:
f = open(filename, "rb")
tags = exifread.process_file(f)
tags = exifreader.get_metadata(filename)
if DATETIME_KEY not in tags:
print(f"No datetime tag found for: {filename}", file=sys.stderr)
print(f"No datetime tag found for: {filename}. Only {tags.keys()}", file=sys.stderr)
continue
ifd_tag: IfdTag = tags[DATETIME_KEY]
match = DATETIME_PATTERN.match(ifd_tag.values)
match = DATETIME_PATTERN.match(tags[DATETIME_KEY])
if match is None:
print(
f"Invalid datetime tag ({tags[DATETIME_KEY]!r}) found for: {filename}",
@ -98,6 +101,8 @@ def cli():
if found_raw is not None:
print(found_raw, "", get_new_name(found_raw, match))
exifreader.terminate()
if __name__ == "__main__":
cli()

@ -19,7 +19,7 @@ VERSION = "0.1.0"
# What packages are required for this module to be executed?
REQUIRED = [
"ExifRead",
"PyExifTool",
"Pillow",
]

Loading…
Cancel
Save