From d9e88e87f96aed40ed5a782b141e17af346b96fa Mon Sep 17 00:00:00 2001 From: tudacs Date: Mon, 17 Dec 2018 22:31:58 +0100 Subject: [PATCH] Fixes sigal aborting if image contains malformed metadata --- sigal/image.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sigal/image.py b/sigal/image.py index 728a1e1..5bee48a 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -235,18 +235,23 @@ def get_exif_data(filename): def get_iptc_data(filename): """Return a dict with the raw IPTC data.""" - img = _read_image(filename) - raw_iptc = IptcImagePlugin.getiptcinfo(img) - # IPTC fields are catalogued in: - # https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata iptc_data = {} - # 2:05 is the IPTC title property - if raw_iptc and (2, 5) in raw_iptc: - iptc_data["title"] = raw_iptc[(2, 5)].decode('utf-8') - # 2:120 is the IPTC description property - if raw_iptc and (2, 120) in raw_iptc: - iptc_data["description"] = raw_iptc[(2, 120)].decode('utf-8') + try: + img = _read_image(filename) + raw_iptc = IptcImagePlugin.getiptcinfo(img) + # IPTC fields are catalogued in: + # https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata + # 2:05 is the IPTC title property + if raw_iptc and (2, 5) in raw_iptc: + iptc_data["title"] = raw_iptc[(2, 5)].decode('utf-8') + + # 2:120 is the IPTC description property + if raw_iptc and (2, 120) in raw_iptc: + iptc_data["description"] = raw_iptc[(2, 120)].decode('utf-8') + except SyntaxError: + print("IPTC Error in %s\n"%filename) + iptc_data = {} return iptc_data