anxdpanic / plugin.video.youtube

Watch your favorite YouTube content on Kodi
https://ytaddon.panicked.xyz/forum
690 stars 114 forks source link

Search History: Cannot remove or rename items with unicode characters (i.e. non-english characters) #815

Closed Miwer closed 4 months ago

Miwer commented 4 months ago

Context

Please provide any relevant information about your setup


Expected Behavior

Be able to remove or rename search history items with non-english characters


Current Behavior

I am unable to remove or rename search history items, that contains non-english characters. They are forever stuck in the search history, unless I clear the history entirely. Clearing history works, but is undesirable if I want to keep other search history items.


Steps to Reproduce

  1. Create new search item with non-english characters.
  2. Try to remove or rename it - plugin throws error.

remove-rename-error


Log

remove:

2024-06-22 21:55:49.183 T:3217822592  NOTICE: [plugin.video.youtube] Running: YouTube (7.0.7+leia.unofficial.1) on Leia (Kodi-18.9) with Python 2.7.16
                                            Path: /kodion/search/remove/
                                            Params: {'q': 'pegasus gr\xc3\xa6sk mytologi'}
2024-06-22 21:55:49.188 T:3217822592   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.UnicodeDecodeError'>
                                            Error Contents: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/plugin.py", line 16, in <module>
                                                plugin_runner.run()
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/plugin_runner.py", line 63, in run
                                                plugin.run(provider, context, new_uri == current_uri)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py", line 157, in run
                                                result, options = provider.navigate(context)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/abstract_provider.py", line 143, in navigate
                                                result = method(context, re_match)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/abstract_provider.py", line 259, in _internal_search
                                                search_history.remove(query)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/sql_store/search_history.py", line 47, in remove
                                                self._remove(self._make_id(search_text))
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/sql_store/search_history.py", line 39, in _make_id
                                                md5_hash.update(search_text.encode('utf-8'))
                                            UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
                                            -->End of Python script error report<--

Rename:

2024-06-22 21:58:23.128 T:3242963840  NOTICE: [plugin.video.youtube] Running: YouTube (7.0.7+leia.unofficial.1) on Leia (Kodi-18.9) with Python 2.7.16
                                            Path: /kodion/search/rename/
                                            Params: {'q': 'pegasus gr\xc3\xa6sk mytologi'}
2024-06-22 21:58:31.906 T:3242963840   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.UnicodeDecodeError'>
                                            Error Contents: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
                                            Traceback (most recent call last):
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/plugin.py", line 16, in <module>
                                                plugin_runner.run()
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/plugin_runner.py", line 63, in run
                                                plugin.run(provider, context, new_uri == current_uri)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py", line 157, in run
                                                result, options = provider.navigate(context)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/abstract_provider.py", line 143, in navigate
                                                result = method(context, re_match)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/abstract_provider.py", line 269, in _internal_search
                                                search_history.rename(query, new_query)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/sql_store/search_history.py", line 43, in rename
                                                self.remove(old_search_text)
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/sql_store/search_history.py", line 47, in remove
                                                self._remove(self._make_id(search_text))
                                              File "/storage/.kodi/addons/plugin.video.youtube/resources/lib/youtube_plugin/kodion/sql_store/search_history.py", line 39, in _make_id
                                                md5_hash.update(search_text.encode('utf-8'))
                                            UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
                                            -->End of Python script error report<--               

Additional Information

I think this bug is related to issue #85 - maybe the search history items need to be specified as unicode somewhere to fix this. I did not have this problem in older versions of the plugin, when repository was available for leia. This only started with the latest unofficial versions downloaded here from github.


MoojMidge commented 4 months ago

I think this bug is related to issue #85 - maybe the search history items need to be specified as unicode somewhere to fix this.

The issue occurs because Python 2 does a lot of things poorly with respect to Unicode handling, like implicitly decoding string data when encoding, but not allowing you to identify the encoding being used when performing the decoding and instead using a default encoding that is almost never useful and results in this error occurring.

I did not have this problem in older versions of the plugin, when repository was available for leia. This only started with the latest unofficial versions downloaded here from github.

When you download these newer version, it is clearly stated that Kodi 18 is unsupported. You can use an older version instead, but if that no longer works, then you are on your own in terms of updates.

There is a simple fix for this that won't impact anything else, but eventually Kodi 18 releases will cease altogether. There aren't that many devices that can run CoreELEC 9.2.8 that can't be updated. Would recommend that you update if your device supports it.

Miwer commented 4 months ago

Thank you for the commit. Unfortunately my device (Odroid C2) has been depricated for some time now, and Coreelec has dropped support for it in their newer versions, so I'm kinda stuck on Kodi 18 for now. I know LibreElec tried to reintroduce support for Odroid C2, but their kernel have other issues, that had me revert to Coreelec. Next step would be replacing the hardware to something newer, but for now it works.