Improve logging and docs

This commit is contained in:
2026-02-01 19:45:51 +01:00
parent da83ed02be
commit 9df80240c4
9 changed files with 461 additions and 47 deletions

View File

@@ -30,13 +30,18 @@ except ImportError: # pragma: no cover - allow running outside Kodi
xbmcaddon = None
from plugin_interface import BasisPlugin
from plugin_helpers import dump_response_html, get_setting_bool, log_url, notify_url
from plugin_helpers import dump_response_html, get_setting_bool, log_error, log_url, notify_url
ADDON_ID = "plugin.video.viewit"
SETTING_BASE_URL = "einschalten_base_url"
GLOBAL_SETTING_LOG_URLS = "debug_log_urls"
GLOBAL_SETTING_DUMP_HTML = "debug_dump_html"
GLOBAL_SETTING_SHOW_URL_INFO = "debug_show_url_info"
GLOBAL_SETTING_LOG_ERRORS = "debug_log_errors"
SETTING_LOG_URLS = "log_urls_einschalten"
SETTING_DUMP_HTML = "dump_html_einschalten"
SETTING_SHOW_URL_INFO = "show_url_info_einschalten"
SETTING_LOG_ERRORS = "log_errors_einschalten"
DEFAULT_BASE_URL = ""
DEFAULT_INDEX_PATH = "/"
@@ -147,16 +152,36 @@ def _extract_ng_state_payload(html: str) -> Dict[str, Any]:
def _notify_url(url: str) -> None:
notify_url(ADDON_ID, heading="einschalten", url=url, enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO)
notify_url(
ADDON_ID,
heading="Einschalten",
url=url,
enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO,
plugin_setting_id=SETTING_SHOW_URL_INFO,
)
def _log_url(url: str, *, kind: str = "VISIT") -> None:
log_url(ADDON_ID, enabled_setting_id=GLOBAL_SETTING_LOG_URLS, log_filename="einschalten_urls.log", url=url, kind=kind)
log_url(
ADDON_ID,
enabled_setting_id=GLOBAL_SETTING_LOG_URLS,
plugin_setting_id=SETTING_LOG_URLS,
log_filename="einschalten_urls.log",
url=url,
kind=kind,
)
def _log_debug_line(message: str) -> None:
try:
log_url(ADDON_ID, enabled_setting_id=GLOBAL_SETTING_LOG_URLS, log_filename="einschalten_debug.log", url=message, kind="DEBUG")
log_url(
ADDON_ID,
enabled_setting_id=GLOBAL_SETTING_LOG_URLS,
plugin_setting_id=SETTING_LOG_URLS,
log_filename="einschalten_debug.log",
url=message,
kind="DEBUG",
)
except Exception:
pass
@@ -168,6 +193,7 @@ def _log_titles(items: list[MovieItem], *, context: str) -> None:
log_url(
ADDON_ID,
enabled_setting_id=GLOBAL_SETTING_LOG_URLS,
plugin_setting_id=SETTING_LOG_URLS,
log_filename="einschalten_titles.log",
url=f"{context}:count={len(items)}",
kind="TITLE",
@@ -176,6 +202,7 @@ def _log_titles(items: list[MovieItem], *, context: str) -> None:
log_url(
ADDON_ID,
enabled_setting_id=GLOBAL_SETTING_LOG_URLS,
plugin_setting_id=SETTING_LOG_URLS,
log_filename="einschalten_titles.log",
url=f"{context}:id={item.id} title={item.title}",
kind="TITLE",
@@ -188,11 +215,22 @@ def _log_response_html(url: str, body: str) -> None:
dump_response_html(
ADDON_ID,
enabled_setting_id=GLOBAL_SETTING_DUMP_HTML,
plugin_setting_id=SETTING_DUMP_HTML,
url=url,
body=body,
filename_prefix="einschalten_response",
)
def _log_error(message: str) -> None:
log_error(
ADDON_ID,
enabled_setting_id=GLOBAL_SETTING_LOG_ERRORS,
plugin_setting_id=SETTING_LOG_ERRORS,
log_filename="einschalten_errors.log",
message=message,
)
def _u_matches(value: Any, expected_path: str) -> bool:
raw = (value or "").strip()
if not raw:
@@ -616,7 +654,8 @@ class EinschaltenPlugin(BasisPlugin):
_log_response_html(resp.url or url, resp.text)
self._detail_html_by_id[movie_id] = resp.text or ""
return resp.text or ""
except Exception:
except Exception as exc:
_log_error(f"GET {url} failed: {exc}")
return ""
def _fetch_watch_payload(self, movie_id: int) -> dict[str, object]:
@@ -637,7 +676,8 @@ class EinschaltenPlugin(BasisPlugin):
_log_response_html(resp.url or url, resp.text)
data = resp.json()
return dict(data) if isinstance(data, dict) else {}
except Exception:
except Exception as exc:
_log_error(f"GET {url} failed: {exc}")
return {}
def _watch_stream_url(self, movie_id: int) -> str: