summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-06-09 22:40:08 +0200
committerJulian T <julian@jtle.dk>2021-06-09 22:40:08 +0200
commit694e6ba04dffa6d032f4b784d599cf4ebb5402f4 (patch)
tree367ad1520dba1a6066fc8c61c805ddfbfa528b40
parentad42a317920bb29794b472d9df5dd320c9c27123 (diff)
Fix timestamp extraction
-rwxr-xr-xbuild.py11
-rw-r--r--shell.nix2
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
];
}