Use exiftool instead because it handles more filetypes
including MP4 (!!!)
This commit is contained in:
parent
df3e79b9e6
commit
556696f0f8
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue