Skip to content

Commit

Permalink
fix: Help pymagic with poorly encoded filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Nov 5, 2017
1 parent d7f1711 commit 7ffef22
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/eyed3/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def __init__(self):
def guess_type(self, filename):
if os.path.splitext(filename)[1] in ID3_MIME_TYPE_EXTENSIONS:
return ID3_MIME_TYPE
return self.from_file(filename)
try:
return self.from_file(filename)
except UnicodeEncodeError as enc_err:
# https://github.com/ahupp/python-magic/pull/144
return self.from_file(filename.encode("utf-8", 'surrogateescape'))


_mime_types = MagicTypes()
Expand Down

0 comments on commit 7ffef22

Please sign in to comment.