im85288 / service.upnext

GNU General Public License v2.0
81 stars 42 forks source link

Unicode issue #234

Closed elgatito closed 3 years ago

elgatito commented 3 years ago

Hello,

I encountered an issue with UpNext when the tv show title has Unicode chars, and tvshowid is empty:

2020-12-09 12:32:51.347 T:140559893907200   ERROR: /home/elgato/.kodi/addons/service.upnext/resources/lib/api.py:193: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

That is an error coming from api.showtitle_to_id.

dagwieers commented 3 years ago

Thanks for reporting. I assume this is when using UpNext with local media, on Kodi v18 or older?

elgatito commented 3 years ago

@dagwieers Oh, sorry, had to give those details.

Yes, it's Kodi 18, so Python2 there. It's not a local media, a video plugin, which sets correct infolabels, but they are according to Kodi language, so tvshowtitle is unicode in this case.

dagwieers commented 3 years ago

@elgatito Interesting, which video plugin is this? Because we compare unicode vs unicode, even on Python 2 (unicode_literals). So I am suspecting that the add-on is not in fact sending us unicode. It is easy to verify if I can look at their code.

elgatito commented 3 years ago

@dagwieers The code of creating a resolved item is here: https://github.com/elgatito/plugin.video.elementum/blob/master/resources/site-packages/elementum/navigation.py#L166

Infolabels come from a backend server, just parsed by python and passed to Kodi via setResolvedUrl. Kodi shows everything in correct Unicode.

dagwieers commented 3 years ago

@elgatito Right, but on Python 2.7 strings are not unicode strings. So you need to do the below (and probably fix code elsewhere) to use unicode literals by default (as you would on Python 3).

from __future__ import absolute_import, division, unicode_literals

And explicitly convert from and to unicode strings for anything that does not use unicode strings (Kodi v18 and older API does not). https://python-future.org/unicode_literals.html

My advice is to use unicode_literals so your code behaves identically on Python 2 and Python 3, and be careful on the edges (where you interface with other software like Kodi). We have two functions to_unicode() and from_unicode() which do the required conversion in a way that works correctly on both Python 2 and Python 3.

Once Kodi v17 (Krypton) and v18 (Leia) are used much less than today we can drop support and remove those calls from the codebase and things will work out as before.

elgatito commented 3 years ago

@dagwieers I will close this issue. I get no error so far, after adding unicode encoding to json. Thanks