Skip to content

Commit

Permalink
gh-127 Fallback to latin if utf-8 decode fails in pyexiftool.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jmathai committed Sep 8, 2016
1 parent 032b90c commit fe70227
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion elodie/external/pyexiftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,14 @@ def execute_json(self, *params):
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.
Expand Down

0 comments on commit fe70227

Please sign in to comment.