Improve logging and docs
This commit is contained in:
@@ -54,10 +54,39 @@ def get_setting_bool(addon_id: str, setting_id: str, *, default: bool = False) -
|
||||
return default
|
||||
|
||||
|
||||
def notify_url(addon_id: str, *, heading: str, url: str, enabled_setting_id: str) -> None:
|
||||
def get_setting_int(addon_id: str, setting_id: str, *, default: int = 0) -> int:
|
||||
if xbmcaddon is None:
|
||||
return default
|
||||
try:
|
||||
addon = xbmcaddon.Addon(addon_id)
|
||||
getter = getattr(addon, "getSettingInt", None)
|
||||
if getter is not None:
|
||||
return int(getter(setting_id))
|
||||
raw = addon.getSetting(setting_id)
|
||||
return int(str(raw).strip())
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def _is_logging_enabled(addon_id: str, *, global_setting_id: str, plugin_setting_id: Optional[str]) -> bool:
|
||||
if not get_setting_bool(addon_id, global_setting_id, default=False):
|
||||
return False
|
||||
if plugin_setting_id:
|
||||
return get_setting_bool(addon_id, plugin_setting_id, default=False)
|
||||
return True
|
||||
|
||||
|
||||
def notify_url(
|
||||
addon_id: str,
|
||||
*,
|
||||
heading: str,
|
||||
url: str,
|
||||
enabled_setting_id: str,
|
||||
plugin_setting_id: Optional[str] = None,
|
||||
) -> None:
|
||||
if xbmcgui is None:
|
||||
return
|
||||
if not get_setting_bool(addon_id, enabled_setting_id, default=False):
|
||||
if not _is_logging_enabled(addon_id, global_setting_id=enabled_setting_id, plugin_setting_id=plugin_setting_id):
|
||||
return
|
||||
try:
|
||||
xbmcgui.Dialog().notification(heading, url, xbmcgui.NOTIFICATION_INFO, 3000)
|
||||
@@ -96,16 +125,92 @@ def _append_text_file(path: str, content: str) -> None:
|
||||
return
|
||||
|
||||
|
||||
def log_url(addon_id: str, *, enabled_setting_id: str, log_filename: str, url: str, kind: str = "VISIT") -> None:
|
||||
if not get_setting_bool(addon_id, enabled_setting_id, default=False):
|
||||
def _rotate_log_file(path: str, *, max_bytes: int, max_files: int) -> None:
|
||||
if max_bytes <= 0 or max_files <= 0:
|
||||
return
|
||||
try:
|
||||
if not os.path.exists(path) or os.path.getsize(path) <= max_bytes:
|
||||
return
|
||||
except Exception:
|
||||
return
|
||||
try:
|
||||
for index in range(max_files - 1, 0, -1):
|
||||
older = f"{path}.{index}"
|
||||
newer = f"{path}.{index + 1}"
|
||||
if os.path.exists(older):
|
||||
if index + 1 > max_files:
|
||||
os.remove(older)
|
||||
else:
|
||||
os.replace(older, newer)
|
||||
os.replace(path, f"{path}.1")
|
||||
except Exception:
|
||||
return
|
||||
|
||||
|
||||
def _prune_dump_files(directory: str, *, prefix: str, max_files: int) -> None:
|
||||
if not directory or max_files <= 0:
|
||||
return
|
||||
try:
|
||||
entries = [
|
||||
os.path.join(directory, name)
|
||||
for name in os.listdir(directory)
|
||||
if name.startswith(prefix) and name.endswith(".html")
|
||||
]
|
||||
if len(entries) <= max_files:
|
||||
return
|
||||
entries.sort(key=lambda path: os.path.getmtime(path))
|
||||
for path in entries[: len(entries) - max_files]:
|
||||
try:
|
||||
os.remove(path)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
return
|
||||
|
||||
|
||||
def log_url(
|
||||
addon_id: str,
|
||||
*,
|
||||
enabled_setting_id: str,
|
||||
log_filename: str,
|
||||
url: str,
|
||||
kind: str = "VISIT",
|
||||
request_id: Optional[str] = None,
|
||||
plugin_setting_id: Optional[str] = None,
|
||||
max_mb_setting_id: str = "log_max_mb",
|
||||
max_files_setting_id: str = "log_max_files",
|
||||
) -> None:
|
||||
if not _is_logging_enabled(addon_id, global_setting_id=enabled_setting_id, plugin_setting_id=plugin_setting_id):
|
||||
return
|
||||
timestamp = datetime.utcnow().isoformat(timespec="seconds") + "Z"
|
||||
line = f"{timestamp}\t{kind}\t{url}\n"
|
||||
request_part = f"\t{request_id}" if request_id else ""
|
||||
line = f"{timestamp}\t{kind}{request_part}\t{url}\n"
|
||||
log_dir = _profile_logs_dir(addon_id)
|
||||
if log_dir:
|
||||
_append_text_file(os.path.join(log_dir, log_filename), line)
|
||||
return
|
||||
_append_text_file(os.path.join(os.path.dirname(__file__), log_filename), line)
|
||||
path = os.path.join(log_dir, log_filename) if log_dir else os.path.join(os.path.dirname(__file__), log_filename)
|
||||
max_mb = get_setting_int(addon_id, max_mb_setting_id, default=5)
|
||||
max_files = get_setting_int(addon_id, max_files_setting_id, default=3)
|
||||
_rotate_log_file(path, max_bytes=max_mb * 1024 * 1024, max_files=max_files)
|
||||
_append_text_file(path, line)
|
||||
|
||||
|
||||
def log_error(
|
||||
addon_id: str,
|
||||
*,
|
||||
enabled_setting_id: str,
|
||||
log_filename: str,
|
||||
message: str,
|
||||
request_id: Optional[str] = None,
|
||||
plugin_setting_id: Optional[str] = None,
|
||||
) -> None:
|
||||
log_url(
|
||||
addon_id,
|
||||
enabled_setting_id=enabled_setting_id,
|
||||
plugin_setting_id=plugin_setting_id,
|
||||
log_filename=log_filename,
|
||||
url=message,
|
||||
kind="ERROR",
|
||||
request_id=request_id,
|
||||
)
|
||||
|
||||
|
||||
def dump_response_html(
|
||||
@@ -115,14 +220,20 @@ def dump_response_html(
|
||||
url: str,
|
||||
body: str,
|
||||
filename_prefix: str,
|
||||
request_id: Optional[str] = None,
|
||||
plugin_setting_id: Optional[str] = None,
|
||||
max_files_setting_id: str = "dump_max_files",
|
||||
) -> None:
|
||||
if not get_setting_bool(addon_id, enabled_setting_id, default=False):
|
||||
if not _is_logging_enabled(addon_id, global_setting_id=enabled_setting_id, plugin_setting_id=plugin_setting_id):
|
||||
return
|
||||
timestamp = datetime.utcnow().strftime("%Y%m%d_%H%M%S_%f")
|
||||
digest = hashlib.md5(url.encode("utf-8")).hexdigest() # nosec - filename only
|
||||
filename = f"{filename_prefix}_{timestamp}_{digest}.html"
|
||||
log_dir = _profile_logs_dir(addon_id)
|
||||
path = os.path.join(log_dir, filename) if log_dir else os.path.join(os.path.dirname(__file__), filename)
|
||||
content = f"<!-- {url} -->\n{body or ''}"
|
||||
request_line = f" request_id={request_id}" if request_id else ""
|
||||
content = f"<!-- {url}{request_line} -->\n{body or ''}"
|
||||
if log_dir:
|
||||
max_files = get_setting_int(addon_id, max_files_setting_id, default=200)
|
||||
_prune_dump_files(log_dir, prefix=filename_prefix, max_files=max_files)
|
||||
_append_text_file(path, content)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -1,9 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<category label="Allgemein">
|
||||
<setting id="debug_log_urls" type="bool" label="Debug: URL-Log aktivieren (global)" default="false" />
|
||||
<setting id="debug_dump_html" type="bool" label="Debug: HTML-Antworten speichern (global)" default="false" />
|
||||
<setting id="debug_show_url_info" type="bool" label="Debug: Aufgerufene URL anzeigen (global)" default="false" />
|
||||
<category label="Logging">
|
||||
<setting id="debug_log_urls" type="bool" label="URL-Logging aktivieren (global)" default="false" />
|
||||
<setting id="debug_dump_html" type="bool" label="HTML-Dumps aktivieren (global)" default="false" />
|
||||
<setting id="debug_show_url_info" type="bool" label="URL-Info anzeigen (global)" default="false" />
|
||||
<setting id="debug_log_errors" type="bool" label="Fehler-Logging aktivieren (global)" default="false" />
|
||||
<setting id="log_max_mb" type="number" label="URL-Log: max. Datei-Größe (MB)" default="5" />
|
||||
<setting id="log_max_files" type="number" label="URL-Log: max. Rotationen" default="3" />
|
||||
<setting id="dump_max_files" type="number" label="HTML-Dumps: max. Dateien pro Plugin" default="200" />
|
||||
<setting id="log_urls_serienstream" type="bool" label="Serienstream: URL-Logging" default="false" />
|
||||
<setting id="dump_html_serienstream" type="bool" label="Serienstream: HTML-Dumps" default="false" />
|
||||
<setting id="show_url_info_serienstream" type="bool" label="Serienstream: URL-Info anzeigen" default="false" />
|
||||
<setting id="log_errors_serienstream" type="bool" label="Serienstream: Fehler loggen" default="false" />
|
||||
<setting id="log_urls_aniworld" type="bool" label="Aniworld: URL-Logging" default="false" />
|
||||
<setting id="dump_html_aniworld" type="bool" label="Aniworld: HTML-Dumps" default="false" />
|
||||
<setting id="show_url_info_aniworld" type="bool" label="Aniworld: URL-Info anzeigen" default="false" />
|
||||
<setting id="log_errors_aniworld" type="bool" label="Aniworld: Fehler loggen" default="false" />
|
||||
<setting id="log_urls_topstreamfilm" type="bool" label="Topstreamfilm: URL-Logging" default="false" />
|
||||
<setting id="dump_html_topstreamfilm" type="bool" label="Topstreamfilm: HTML-Dumps" default="false" />
|
||||
<setting id="show_url_info_topstreamfilm" type="bool" label="Topstreamfilm: URL-Info anzeigen" default="false" />
|
||||
<setting id="log_errors_topstreamfilm" type="bool" label="Topstreamfilm: Fehler loggen" default="false" />
|
||||
<setting id="log_urls_einschalten" type="bool" label="Einschalten: URL-Logging" default="false" />
|
||||
<setting id="dump_html_einschalten" type="bool" label="Einschalten: HTML-Dumps" default="false" />
|
||||
<setting id="show_url_info_einschalten" type="bool" label="Einschalten: URL-Info anzeigen" default="false" />
|
||||
<setting id="log_errors_einschalten" type="bool" label="Einschalten: Fehler loggen" default="false" />
|
||||
</category>
|
||||
<category label="TopStream">
|
||||
<setting id="topstream_base_url" type="text" label="Domain (BASE_URL)" default="https://topstreamfilm.live" />
|
||||
|
||||
Reference in New Issue
Block a user