From 694e6ba04dffa6d032f4b784d599cf4ebb5402f4 Mon Sep 17 00:00:00 2001 From: Julian T Date: Wed, 9 Jun 2021 22:40:08 +0200 Subject: Fix timestamp extraction --- build.py | 11 +++++++---- shell.nix | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build.py b/build.py index f018b94..d061efb 100755 --- a/build.py +++ b/build.py @@ -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): diff --git a/shell.nix b/shell.nix index d452969..3edf0b2 100644 --- a/shell.nix +++ b/shell.nix @@ -2,6 +2,6 @@ pkgs.mkShell { buildInputs = with pythonPackages; [ - jinja2 schema pillow pyyaml + jinja2 pillow pyyaml pkgs.exiftool ]; } -- cgit v1.2.3