moreginger / xbmc-plugin.video.ted.talks

GNU General Public License v2.0
18 stars 20 forks source link

UnicodeDecodeError due to reading ISO-639-2_utf-8.txt as ASCII #79

Closed dreamlayers closed 2 years ago

dreamlayers commented 3 years ago

I'm using addon version 5.0.0 with Kodi 2:19.1+dfsg2-2 and Python 3.9.4-1 in Ubuntu 21.10. Video playback failed, because resources/lib/model/language_mapping.py tried to read ISO-639-2_utf-8.txt as ASCII, but the file is UTF-8. The Python 3 built in open() has an encoding parameter, so this can be fixed using f = open(file_path, 'r', encoding="utf-8") at https://github.com/moreginger/xbmc-plugin.video.ted.talks/blob/72238a15d52f4f661bfff2738c97b208d719c276/resources/lib/model/language_mapping.py#L16 Though that probably won't work with Python 2. Here's the whole Python error from kodi.log:

Error Type: <class 'UnicodeDecodeError'>
Error Contents: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
Traceback (most recent call last):
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/default.py", line 14, in <module>
   ted_talks.Main(args_map=args_map).run()
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/resources/lib/ted_talks.py", line 336, in run
   modes[mode].run(self.args_map)
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/resources/lib/ted_talks.py", line 148, in run
   self.run_internal(args)
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/resources/lib/ted_talks.py", line 166, in run_internal
   self.ui.playVideo(args['url'], args['icon'] if 'icon' in args else None)
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/resources/lib/ted_talks.py", line 70, in playVideo
   subs_language = settings.get_subtitle_languages()
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/resources/lib/settings.py", line 38, in get_subtitle_languages
   code = language_mapping.get_language_code(xbmc_language)
 File "/home/bgjenero/.kodi/addons/plugin.video.ted.talks/resources/lib/model/language_mapping.py", line 18, in get_language_code
   for line in f:
 File "/usr/lib/python3.9/encodings/ascii.py", line 26, in decode
   return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
moreginger commented 3 years ago

Thanks for this! I'll get a fix done as soon as I can... it looks like there are some other issues with the subtitles / playback since I last worked on it.