Merge pull request #128 from jmathai/utf-8-gh-127

gh-127 Fallback to latin if utf-8 decode fails in pyexiftool.py
This commit is contained in:
Jaisen Mathai 2016-09-07 20:59:45 -07:00 committed by GitHub
commit a197adb19f
1 changed files with 8 additions and 1 deletions

View File

@ -304,7 +304,14 @@ class ExifTool(object):
as Unicode strings in Python 3.x. as Unicode strings in Python 3.x.
""" """
params = map(fsencode, params) 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): def get_metadata_batch(self, filenames):
"""Return all meta-data for the given files. """Return all meta-data for the given files.