diff --git a/lib/inputstreamhelper/kodiutils.py b/lib/inputstreamhelper/kodiutils.py index aa107c47..73645149 100644 --- a/lib/inputstreamhelper/kodiutils.py +++ b/lib/inputstreamhelper/kodiutils.py @@ -7,6 +7,13 @@ import xbmc import xbmcaddon from xbmcgui import DialogProgress, DialogProgressBG + +try: # Kodi v19 or newer + from xbmcvfs import translatePath +except ImportError: # Kodi v18 and older + # pylint: disable=ungrouped-imports + from xbmc import translatePath + from .unicodes import from_unicode, to_unicode # NOTE: We need to explicitly add the add-on id here! @@ -60,7 +67,7 @@ def kodi_version_major(): def translate_path(path): """Translate special xbmc paths""" - return to_unicode(xbmc.translatePath(from_unicode(path))) + return to_unicode(translatePath(from_unicode(path))) def get_addon_info(key): diff --git a/tests/xbmcvfs.py b/tests/xbmcvfs.py index dd6bb8ca..cbb65edd 100644 --- a/tests/xbmcvfs.py +++ b/tests/xbmcvfs.py @@ -82,3 +82,16 @@ def mkdirs(path): def rmdir(path): """A reimplementation of the xbmcvfs rmdir() function""" return os.rmdir(path) + + +def translatePath(path): + """A stub implementation of the xbmc translatePath() function""" + if path.startswith('special://home'): + return path.replace('special://home', os.path.join(os.getcwd(), 'tests/')) + if path.startswith('special://masterprofile'): + return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata/')) + if path.startswith('special://profile'): + return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata/')) + if path.startswith('special://userdata'): + return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata/')) + return path