dev: import resolveurl from addon path when dependency is soft
This commit is contained in:
@@ -7,6 +7,7 @@ zu einer abspielbaren Media-URL (inkl. evtl. Header-Suffix) aufgelöst werden.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
import sys
|
||||
|
||||
_LAST_RESOLVE_ERROR = ""
|
||||
|
||||
@@ -20,9 +21,29 @@ def resolve(url: str) -> Optional[str]:
|
||||
_LAST_RESOLVE_ERROR = ""
|
||||
if not url:
|
||||
return None
|
||||
resolveurl = None
|
||||
try:
|
||||
import resolveurl # type: ignore
|
||||
import resolveurl as _resolveurl # type: ignore
|
||||
resolveurl = _resolveurl
|
||||
except Exception:
|
||||
# Ohne harte addon.xml-Abhaengigkeit liegt resolveurl ggf. nicht im Python-Pfad.
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user