diff --git a/pymediainfo/__init__.py b/pymediainfo/__init__.py index f5d0595..73c8383 100644 --- a/pymediainfo/__init__.py +++ b/pymediainfo/__init__.py @@ -1,5 +1,6 @@ -import json import os +import locale +import json import sys from pkg_resources import get_distribution import xml.etree.ElementTree as ET @@ -92,6 +93,13 @@ def parse(filename): # Create a MediaInfo handle handle = lib.MediaInfo_New() lib.MediaInfo_Option(handle, "CharSet", "UTF-8") + # Fix for https://github.com/sbraz/pymediainfo/issues/22 + # Python 2 does not change LC_CTYPE + # at startup: https://bugs.python.org/issue6203 + if (sys.version_info.major < 3 and os.name == "posix" + and not sys.platform == "darwin" + and locale.getlocale() == (None, None)): + locale.setlocale(locale.LC_CTYPE, locale.getdefaultlocale()) lib.MediaInfo_Option(None, "Inform", "XML") lib.MediaInfo_Option(None, "Complete", "1") lib.MediaInfo_Open(handle, filename) diff --git a/tests/test.py b/tests/test.py index 6c81297..012b765 100644 --- a/tests/test.py +++ b/tests/test.py @@ -72,8 +72,6 @@ def test_parse_file_with_unicode_tags(self): "l’aÿ d’âge mûr & cætera !" ) -@unittest.skipIf(sys.version_info.major < 3, "Currently broken " - "see https://github.com/sbraz/pymediainfo/issues/22") class MediaInfoUnicodeFileNameTest(unittest.TestCase): def setUp(self): self.mi = MediaInfo.parse(os.path.join(data_dir, "accentué.txt"))