Improve logging and docs
This commit is contained in:
@@ -29,7 +29,7 @@ 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, get_setting_string, log_url, notify_url
|
||||
from plugin_helpers import dump_response_html, get_setting_bool, get_setting_string, log_error, log_url, notify_url
|
||||
from http_session_pool import get_requests_session
|
||||
from regex_patterns import DIGITS, SEASON_EPISODE_TAG, SEASON_EPISODE_URL, STAFFEL_NUM_IN_URL
|
||||
|
||||
@@ -49,6 +49,11 @@ ADDON_ID = "plugin.video.viewit"
|
||||
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_aniworld"
|
||||
SETTING_DUMP_HTML = "dump_html_aniworld"
|
||||
SETTING_SHOW_URL_INFO = "show_url_info_aniworld"
|
||||
SETTING_LOG_ERRORS = "log_errors_aniworld"
|
||||
HEADERS = {
|
||||
"User-Agent": "Mozilla/5.0 (Kodi; ViewIt) AppleWebKit/537.36 (KHTML, like Gecko)",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
@@ -124,12 +129,25 @@ def _absolute_url(href: str) -> str:
|
||||
|
||||
|
||||
def _log_url(url: str, *, kind: str = "VISIT") -> None:
|
||||
log_url(ADDON_ID, enabled_setting_id=GLOBAL_SETTING_LOG_URLS, log_filename="aniworld_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="aniworld_urls.log",
|
||||
url=url,
|
||||
kind=kind,
|
||||
)
|
||||
|
||||
|
||||
def _log_visit(url: str) -> None:
|
||||
_log_url(url, kind="VISIT")
|
||||
notify_url(ADDON_ID, heading="AniWorld", url=url, enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO)
|
||||
notify_url(
|
||||
ADDON_ID,
|
||||
heading="AniWorld",
|
||||
url=url,
|
||||
enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO,
|
||||
plugin_setting_id=SETTING_SHOW_URL_INFO,
|
||||
)
|
||||
|
||||
|
||||
def _log_parsed_url(url: str) -> None:
|
||||
@@ -140,12 +158,23 @@ 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="aniworld_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="aniworld_errors.log",
|
||||
message=message,
|
||||
)
|
||||
|
||||
|
||||
def _normalize_search_text(value: str) -> str:
|
||||
value = (value or "").casefold()
|
||||
value = re.sub(r"[^a-z0-9]+", " ", value)
|
||||
@@ -192,8 +221,12 @@ def _get_soup(url: str, *, session: Optional[RequestsSession] = None) -> Beautif
|
||||
_ensure_requests()
|
||||
_log_visit(url)
|
||||
sess = session or get_requests_session("aniworld", headers=HEADERS)
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
except Exception as exc:
|
||||
_log_error(f"GET {url} failed: {exc}")
|
||||
raise
|
||||
if response.url and response.url != url:
|
||||
_log_url(response.url, kind="REDIRECT")
|
||||
_log_response_html(url, response.text)
|
||||
@@ -206,8 +239,12 @@ def _get_soup_simple(url: str) -> BeautifulSoupT:
|
||||
_ensure_requests()
|
||||
_log_visit(url)
|
||||
sess = get_requests_session("aniworld", headers=HEADERS)
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
except Exception as exc:
|
||||
_log_error(f"GET {url} failed: {exc}")
|
||||
raise
|
||||
if response.url and response.url != url:
|
||||
_log_url(response.url, kind="REDIRECT")
|
||||
_log_response_html(url, response.text)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -37,7 +37,7 @@ except ImportError: # pragma: no cover - allow running outside Kodi
|
||||
xbmcgui = None
|
||||
|
||||
from plugin_interface import BasisPlugin
|
||||
from plugin_helpers import dump_response_html, get_setting_bool, get_setting_string, log_url, notify_url
|
||||
from plugin_helpers import dump_response_html, get_setting_bool, get_setting_string, log_error, log_url, notify_url
|
||||
from http_session_pool import get_requests_session
|
||||
from regex_patterns import SEASON_EPISODE_TAG, SEASON_EPISODE_URL
|
||||
|
||||
@@ -57,6 +57,11 @@ ADDON_ID = "plugin.video.viewit"
|
||||
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_serienstream"
|
||||
SETTING_DUMP_HTML = "dump_html_serienstream"
|
||||
SETTING_SHOW_URL_INFO = "show_url_info_serienstream"
|
||||
SETTING_LOG_ERRORS = "log_errors_serienstream"
|
||||
HEADERS = {
|
||||
"User-Agent": "Mozilla/5.0 (Kodi; ViewIt) AppleWebKit/537.36 (KHTML, like Gecko)",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
@@ -169,11 +174,24 @@ def _get_setting_bool(setting_id: str, *, default: bool = False) -> bool:
|
||||
|
||||
|
||||
def _notify_url(url: str) -> None:
|
||||
notify_url(ADDON_ID, heading="Serienstream", url=url, enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO)
|
||||
notify_url(
|
||||
ADDON_ID,
|
||||
heading="Serienstream",
|
||||
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="serienstream_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="serienstream_urls.log",
|
||||
url=url,
|
||||
kind=kind,
|
||||
)
|
||||
|
||||
|
||||
def _log_parsed_url(url: str) -> None:
|
||||
@@ -184,12 +202,23 @@ 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="s_to_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="serienstream_errors.log",
|
||||
message=message,
|
||||
)
|
||||
|
||||
|
||||
def _ensure_requests() -> None:
|
||||
if requests is None or BeautifulSoup is None:
|
||||
raise RuntimeError("requests/bs4 sind nicht verfuegbar.")
|
||||
@@ -213,8 +242,12 @@ def _get_soup(url: str, *, session: Optional[RequestsSession] = None) -> Beautif
|
||||
_ensure_requests()
|
||||
_log_visit(url)
|
||||
sess = session or get_requests_session("serienstream", headers=HEADERS)
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
except Exception as exc:
|
||||
_log_error(f"GET {url} failed: {exc}")
|
||||
raise
|
||||
if response.url and response.url != url:
|
||||
_log_url(response.url, kind="REDIRECT")
|
||||
_log_response_html(url, response.text)
|
||||
@@ -227,8 +260,12 @@ def _get_soup_simple(url: str) -> BeautifulSoupT:
|
||||
_ensure_requests()
|
||||
_log_visit(url)
|
||||
sess = get_requests_session("serienstream", headers=HEADERS)
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
except Exception as exc:
|
||||
_log_error(f"GET {url} failed: {exc}")
|
||||
raise
|
||||
if response.url and response.url != url:
|
||||
_log_url(response.url, kind="REDIRECT")
|
||||
_log_response_html(url, response.text)
|
||||
|
||||
@@ -44,7 +44,7 @@ except ImportError: # pragma: no cover - allow running outside Kodi
|
||||
xbmcgui = 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
|
||||
from regex_patterns import DIGITS
|
||||
|
||||
if TYPE_CHECKING: # pragma: no cover
|
||||
@@ -61,6 +61,11 @@ DEFAULT_BASE_URL = "https://www.meineseite"
|
||||
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_topstreamfilm"
|
||||
SETTING_DUMP_HTML = "dump_html_topstreamfilm"
|
||||
SETTING_SHOW_URL_INFO = "show_url_info_topstreamfilm"
|
||||
SETTING_LOG_ERRORS = "log_errors_topstreamfilm"
|
||||
SETTING_GENRE_MAX_PAGES = "topstream_genre_max_pages"
|
||||
DEFAULT_TIMEOUT = 20
|
||||
DEFAULT_PREFERRED_HOSTERS = ["supervideo", "dropload", "voe"]
|
||||
@@ -348,20 +353,43 @@ class TopstreamfilmPlugin(BasisPlugin):
|
||||
return default
|
||||
|
||||
def _notify_url(self, url: str) -> None:
|
||||
notify_url(ADDON_ID, heading=self.name, url=url, enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO)
|
||||
notify_url(
|
||||
ADDON_ID,
|
||||
heading=self.name,
|
||||
url=url,
|
||||
enabled_setting_id=GLOBAL_SETTING_SHOW_URL_INFO,
|
||||
plugin_setting_id=SETTING_SHOW_URL_INFO,
|
||||
)
|
||||
|
||||
def _log_url(self, url: str, *, kind: str = "VISIT") -> None:
|
||||
log_url(ADDON_ID, enabled_setting_id=GLOBAL_SETTING_LOG_URLS, log_filename="topstream_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="topstream_urls.log",
|
||||
url=url,
|
||||
kind=kind,
|
||||
)
|
||||
|
||||
def _log_response_html(self, 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="topstream_response",
|
||||
)
|
||||
|
||||
def _log_error(self, message: str) -> None:
|
||||
log_error(
|
||||
ADDON_ID,
|
||||
enabled_setting_id=GLOBAL_SETTING_LOG_ERRORS,
|
||||
plugin_setting_id=SETTING_LOG_ERRORS,
|
||||
log_filename="topstream_errors.log",
|
||||
message=message,
|
||||
)
|
||||
|
||||
def capabilities(self) -> set[str]:
|
||||
return {"genres", "popular_series"}
|
||||
|
||||
@@ -557,8 +585,12 @@ class TopstreamfilmPlugin(BasisPlugin):
|
||||
session = self._get_session()
|
||||
self._log_url(url, kind="VISIT")
|
||||
self._notify_url(url)
|
||||
response = session.get(url, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = session.get(url, timeout=DEFAULT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
except Exception as exc:
|
||||
self._log_error(f"GET {url} failed: {exc}")
|
||||
raise
|
||||
self._log_url(response.url, kind="OK")
|
||||
self._log_response_html(response.url, response.text)
|
||||
return BeautifulSoup(response.text, "html.parser")
|
||||
@@ -803,12 +835,16 @@ class TopstreamfilmPlugin(BasisPlugin):
|
||||
request_url = f"{url}?{urlencode(params)}"
|
||||
self._log_url(request_url, kind="GET")
|
||||
self._notify_url(request_url)
|
||||
response = session.get(
|
||||
url,
|
||||
params=params,
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = session.get(
|
||||
url,
|
||||
params=params,
|
||||
timeout=DEFAULT_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
except Exception as exc:
|
||||
self._log_error(f"GET {request_url} failed: {exc}")
|
||||
raise
|
||||
self._log_url(response.url, kind="OK")
|
||||
self._log_response_html(response.url, response.text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user