diff options
author | Julian T <julian@jtle.dk> | 2021-06-09 22:40:08 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-06-09 22:40:08 +0200 |
commit | 694e6ba04dffa6d032f4b784d599cf4ebb5402f4 (patch) | |
tree | 367ad1520dba1a6066fc8c61c805ddfbfa528b40 | |
parent | ad42a317920bb29794b472d9df5dd320c9c27123 (diff) |
Fix timestamp extraction
-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 ]; } |