From fe70227c7170e01c8377de7f9770e761eab52036 Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Wed, 7 Sep 2016 20:51:57 -0700 Subject: [PATCH] gh-127 Fallback to latin if utf-8 decode fails in pyexiftool.py --- elodie/external/pyexiftool.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/elodie/external/pyexiftool.py b/elodie/external/pyexiftool.py index f6850f6..0ba18bb 100644 --- a/elodie/external/pyexiftool.py +++ b/elodie/external/pyexiftool.py @@ -304,7 +304,14 @@ class ExifTool(object): as Unicode strings in Python 3.x. """ params = map(fsencode, params) - return json.loads(self.execute(b"-j", *params).decode("utf-8")) + # Some latin bytes won't decode to utf-8. + # Try utf-8 and fallback to latin. + # http://stackoverflow.com/a/5552623/1318758 + # https://github.com/jmathai/elodie/issues/127 + try: + return json.loads(self.execute(b"-j", *params).decode("utf-8")) + except UnicodeDecodeError as e: + return json.loads(self.execute(b"-j", *params).decode("latin-1")) def get_metadata_batch(self, filenames): """Return all meta-data for the given files.