dev: add kodi-six and dependency paths for resolveurl import
This commit is contained in:
@@ -12,6 +12,31 @@ import sys
|
|||||||
_LAST_RESOLVE_ERROR = ""
|
_LAST_RESOLVE_ERROR = ""
|
||||||
|
|
||||||
|
|
||||||
|
def _append_kodi_dependency_paths() -> None:
|
||||||
|
"""Ensure optional Kodi module dependencies are importable."""
|
||||||
|
try:
|
||||||
|
import xbmcaddon # type: ignore
|
||||||
|
import xbmcvfs # type: ignore
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
for addon_id in ("script.module.resolveurl", "script.module.kodi-six", "script.module.six"):
|
||||||
|
try:
|
||||||
|
addon = xbmcaddon.Addon(addon_id)
|
||||||
|
addon_path = addon.getAddonInfo("path") or ""
|
||||||
|
except Exception:
|
||||||
|
addon_path = ""
|
||||||
|
if not addon_path:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
addon_path = xbmcvfs.translatePath(addon_path)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
lib_path = f"{addon_path}/lib"
|
||||||
|
for candidate in (lib_path, addon_path):
|
||||||
|
if candidate and candidate not in sys.path:
|
||||||
|
sys.path.append(candidate)
|
||||||
|
|
||||||
|
|
||||||
def get_last_error() -> str:
|
def get_last_error() -> str:
|
||||||
return str(_LAST_RESOLVE_ERROR or "")
|
return str(_LAST_RESOLVE_ERROR or "")
|
||||||
|
|
||||||
@@ -26,19 +51,9 @@ def resolve(url: str) -> Optional[str]:
|
|||||||
import resolveurl as _resolveurl # type: ignore
|
import resolveurl as _resolveurl # type: ignore
|
||||||
resolveurl = _resolveurl
|
resolveurl = _resolveurl
|
||||||
except Exception:
|
except Exception:
|
||||||
# Ohne harte addon.xml-Abhaengigkeit liegt resolveurl ggf. nicht im Python-Pfad.
|
# Ohne harte addon.xml-Abhaengigkeit liegen optionale libs ggf. nicht im Python-Pfad.
|
||||||
|
_append_kodi_dependency_paths()
|
||||||
try:
|
try:
|
||||||
import xbmcaddon # type: ignore
|
|
||||||
import xbmcvfs # type: ignore
|
|
||||||
|
|
||||||
addon = xbmcaddon.Addon("script.module.resolveurl")
|
|
||||||
addon_path = addon.getAddonInfo("path") or ""
|
|
||||||
if addon_path:
|
|
||||||
lib_path = xbmcvfs.translatePath(f"{addon_path}/lib")
|
|
||||||
if lib_path and lib_path not in sys.path:
|
|
||||||
sys.path.append(lib_path)
|
|
||||||
if addon_path and addon_path not in sys.path:
|
|
||||||
sys.path.append(addon_path)
|
|
||||||
import resolveurl as _resolveurl # type: ignore
|
import resolveurl as _resolveurl # type: ignore
|
||||||
resolveurl = _resolveurl
|
resolveurl = _resolveurl
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user