From c0bd6acda6f8749f3a0e532510884b30ee482d10 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 28 Jun 2026 18:16:58 +0200 Subject: [PATCH] fix: add PIL fallback for CR2 EXIF (piexif alone can't parse some CR2) --- organize.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/organize.py b/organize.py index 716be90..ce7f968 100644 --- a/organize.py +++ b/organize.py @@ -196,6 +196,22 @@ def _read_cr2_exif(path: Path) -> str | None: return raw_val.decode('utf-8') except Exception: pass + + # Fallback: PIL can read EXIF from CR2's embedded JPEG preview + try: + from PIL import Image + from PIL.ExifTags import TAGS + img = Image.open(path) + raw = img._getexif() + img.close() + if raw: + tag_map = {v: k for k, v in TAGS.items()} + for tag_name in ('DateTimeOriginal', 'DateTime'): + tag_code = tag_map.get(tag_name) + if tag_code and tag_code in raw: + return raw[tag_code] + except Exception: + pass return None