dev: import resolveurl from addon path when dependency is soft

This commit is contained in:
2026-02-24 20:41:08 +01:00
parent 6bdd4659bb
commit 16e0c77162

View File

@@ -7,6 +7,7 @@ zu einer abspielbaren Media-URL (inkl. evtl. Header-Suffix) aufgelöst werden.
from __future__ import annotations from __future__ import annotations
from typing import Optional from typing import Optional
import sys
_LAST_RESOLVE_ERROR = "" _LAST_RESOLVE_ERROR = ""
@@ -20,11 +21,31 @@ def resolve(url: str) -> Optional[str]:
_LAST_RESOLVE_ERROR = "" _LAST_RESOLVE_ERROR = ""
if not url: if not url:
return None return None
resolveurl = None
try: try:
import resolveurl # type: ignore import resolveurl as _resolveurl # type: ignore
resolveurl = _resolveurl
except Exception: except Exception:
_LAST_RESOLVE_ERROR = "resolveurl missing" # Ohne harte addon.xml-Abhaengigkeit liegt resolveurl ggf. nicht im Python-Pfad.
return None 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
resolveurl = _resolveurl
except Exception:
resolveurl = None
if resolveurl is None:
_LAST_RESOLVE_ERROR = "resolveurl missing"
return None
try: try:
hosted = getattr(resolveurl, "HostedMediaFile", None) hosted = getattr(resolveurl, "HostedMediaFile", None)