diff options
-rwxr-xr-x | build.py | 11 | ||||
-rw-r--r-- | shell.nix | 2 |
2 files changed, 8 insertions, 5 deletions
@@ -1,6 +1,7 @@ #!/usr/bin/env python3 import jinja2 import PIL.Image +import subprocess import PIL.ImageOps import argparse import yaml @@ -115,6 +116,7 @@ class ImageLocation: print(f"Removing file {fname}") os.remove(fname) + class Image: def __init__(self, filename): self.name = os.path.basename(filename) @@ -127,14 +129,15 @@ class Image: self.load_metadata() def load_metadata(self): + result = subprocess.run(["exiftool", "-s", "-s", "-s", "-DateTimeOriginal", self.filename], stdout = subprocess.PIPE) + taken_str = result.stdout.decode("utf-8").strip() + try: - with PIL.Image.open(self.filename) as im: - taken_str = im.getexif()[36867] - except KeyError: + self.taken = datetime.strptime(taken_str, "%Y:%m:%d %H:%M:%S") + except ValueError: print(f"Could not load date from image {self.filename}") return - self.taken = datetime.strptime(taken_str, "%Y:%m:%d %H:%M:%S") def value_or_default(val, default=None): @@ -2,6 +2,6 @@ pkgs.mkShell { buildInputs = with pythonPackages; [ - jinja2 schema pillow pyyaml + jinja2 pillow pyyaml pkgs.exiftool ]; } |