gh-127 Fallback to latin if utf-8 decode fails in pyexiftool.py
This commit is contained in:
parent
032b90c861
commit
fe70227c71
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue