Compare commits
2 Commits
nightly-20
...
1ee15cd104
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ee15cd104 | |||
| b56757f42a |
14
README.md
14
README.md
@@ -29,6 +29,20 @@ Es durchsucht Provider und startet Streams.
|
|||||||
- Plugins: `addon/plugins/*_plugin.py`
|
- Plugins: `addon/plugins/*_plugin.py`
|
||||||
- Settings: `addon/resources/settings.xml`
|
- Settings: `addon/resources/settings.xml`
|
||||||
|
|
||||||
|
## TMDB API Key einrichten
|
||||||
|
- TMDB Account anlegen und API Key (v3) erstellen: `https://www.themoviedb.org/settings/api`
|
||||||
|
- In Kodi das ViewIT Addon oeffnen: `Einstellungen -> TMDB`
|
||||||
|
- `TMDB aktivieren` einschalten
|
||||||
|
- `TMDB API Key` eintragen
|
||||||
|
- Optional `TMDB Sprache` setzen (z. B. `de-DE`)
|
||||||
|
- Optional die Anzeige-Optionen aktivieren/deaktivieren:
|
||||||
|
- `TMDB Beschreibung anzeigen`
|
||||||
|
- `TMDB Poster und Vorschaubild anzeigen`
|
||||||
|
- `TMDB Fanart/Backdrop anzeigen`
|
||||||
|
- `TMDB Bewertung anzeigen`
|
||||||
|
- `TMDB Stimmen anzeigen`
|
||||||
|
- `TMDB Besetzung anzeigen`
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
- Dev Pakete installieren: `./.venv/bin/pip install -r requirements-dev.txt`
|
- Dev Pakete installieren: `./.venv/bin/pip install -r requirements-dev.txt`
|
||||||
- Tests starten: `./.venv/bin/pytest`
|
- Tests starten: `./.venv/bin/pytest`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<addon id="plugin.video.viewit" name="ViewIt" version="0.1.57" provider-name="ViewIt">
|
<addon id="plugin.video.viewit" name="ViewIt" version="0.1.56" provider-name="ViewIt">
|
||||||
<requires>
|
<requires>
|
||||||
<import addon="xbmc.python" version="3.0.0" />
|
<import addon="xbmc.python" version="3.0.0" />
|
||||||
<import addon="script.module.requests" />
|
<import addon="script.module.requests" />
|
||||||
|
|||||||
249
addon/default.py
249
addon/default.py
@@ -8,7 +8,6 @@ ruft Plugin-Implementierungen auf und startet die Wiedergabe.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import atexit
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import importlib.util
|
import importlib.util
|
||||||
@@ -103,13 +102,6 @@ except ImportError: # pragma: no cover - allow importing outside Kodi (e.g. lin
|
|||||||
xbmcplugin = _XbmcPluginStub()
|
xbmcplugin = _XbmcPluginStub()
|
||||||
|
|
||||||
from plugin_interface import BasisPlugin
|
from plugin_interface import BasisPlugin
|
||||||
from http_session_pool import close_all_sessions
|
|
||||||
from metadata_utils import (
|
|
||||||
collect_plugin_metadata as _collect_plugin_metadata,
|
|
||||||
merge_metadata as _merge_metadata,
|
|
||||||
metadata_policy as _metadata_policy_impl,
|
|
||||||
needs_tmdb as _needs_tmdb,
|
|
||||||
)
|
|
||||||
from tmdb import TmdbCastMember, fetch_tv_episode_credits, lookup_movie, lookup_tv_season, lookup_tv_season_summary, lookup_tv_show
|
from tmdb import TmdbCastMember, fetch_tv_episode_credits, lookup_movie, lookup_tv_season, lookup_tv_season_summary, lookup_tv_show
|
||||||
|
|
||||||
PLUGIN_DIR = Path(__file__).with_name("plugins")
|
PLUGIN_DIR = Path(__file__).with_name("plugins")
|
||||||
@@ -124,22 +116,8 @@ _TMDB_LOG_PATH: str | None = None
|
|||||||
_GENRE_TITLES_CACHE: dict[tuple[str, str], list[str]] = {}
|
_GENRE_TITLES_CACHE: dict[tuple[str, str], list[str]] = {}
|
||||||
_ADDON_INSTANCE = None
|
_ADDON_INSTANCE = None
|
||||||
_PLAYSTATE_CACHE: dict[str, dict[str, object]] | None = None
|
_PLAYSTATE_CACHE: dict[str, dict[str, object]] | None = None
|
||||||
_PLAYSTATE_LOCK = threading.RLock()
|
|
||||||
_TMDB_LOCK = threading.RLock()
|
|
||||||
WATCHED_THRESHOLD = 0.9
|
WATCHED_THRESHOLD = 0.9
|
||||||
|
|
||||||
atexit.register(close_all_sessions)
|
|
||||||
|
|
||||||
|
|
||||||
def _tmdb_cache_get(cache: dict, key, default=None):
|
|
||||||
with _TMDB_LOCK:
|
|
||||||
return cache.get(key, default)
|
|
||||||
|
|
||||||
|
|
||||||
def _tmdb_cache_set(cache: dict, key, value) -> None:
|
|
||||||
with _TMDB_LOCK:
|
|
||||||
cache[key] = value
|
|
||||||
|
|
||||||
|
|
||||||
def _tmdb_prefetch_concurrency() -> int:
|
def _tmdb_prefetch_concurrency() -> int:
|
||||||
"""Max number of concurrent TMDB lookups when prefetching metadata for lists."""
|
"""Max number of concurrent TMDB lookups when prefetching metadata for lists."""
|
||||||
@@ -177,19 +155,12 @@ def _busy_close() -> None:
|
|||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _busy_dialog(message: str = "Bitte warten...", *, heading: str = "Bitte warten"):
|
def _busy_dialog():
|
||||||
"""Progress-Dialog statt Spinner, mit kurzem Status-Text."""
|
_busy_open()
|
||||||
with _progress_dialog(heading, message) as progress:
|
|
||||||
progress(10, message)
|
|
||||||
|
|
||||||
def _update(step_message: str, percent: int | None = None) -> bool:
|
|
||||||
pct = 50 if percent is None else max(5, min(95, int(percent)))
|
|
||||||
return progress(pct, step_message or message)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield _update
|
yield
|
||||||
finally:
|
finally:
|
||||||
progress(100, "Fertig")
|
_busy_close()
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
@@ -231,33 +202,6 @@ def _progress_dialog(heading: str, message: str = ""):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _method_accepts_kwarg(method: object, kwarg_name: str) -> bool:
|
|
||||||
if not callable(method):
|
|
||||||
return False
|
|
||||||
try:
|
|
||||||
signature = inspect.signature(method)
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
for param in signature.parameters.values():
|
|
||||||
if param.kind == inspect.Parameter.VAR_KEYWORD:
|
|
||||||
return True
|
|
||||||
if param.name == kwarg_name and param.kind in (
|
|
||||||
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
||||||
inspect.Parameter.KEYWORD_ONLY,
|
|
||||||
):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _call_plugin_search(plugin: BasisPlugin, query: str, *, progress_callback=None):
|
|
||||||
method = getattr(plugin, "search_titles", None)
|
|
||||||
if not callable(method):
|
|
||||||
raise RuntimeError("Plugin hat keine gueltige search_titles Methode.")
|
|
||||||
if progress_callback is not None and _method_accepts_kwarg(method, "progress_callback"):
|
|
||||||
return method(query, progress_callback=progress_callback)
|
|
||||||
return method(query)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_handle() -> int:
|
def _get_handle() -> int:
|
||||||
return int(sys.argv[1]) if len(sys.argv) > 1 else -1
|
return int(sys.argv[1]) if len(sys.argv) > 1 else -1
|
||||||
|
|
||||||
@@ -298,7 +242,6 @@ def _playstate_path() -> str:
|
|||||||
|
|
||||||
def _load_playstate() -> dict[str, dict[str, object]]:
|
def _load_playstate() -> dict[str, dict[str, object]]:
|
||||||
global _PLAYSTATE_CACHE
|
global _PLAYSTATE_CACHE
|
||||||
with _PLAYSTATE_LOCK:
|
|
||||||
if _PLAYSTATE_CACHE is not None:
|
if _PLAYSTATE_CACHE is not None:
|
||||||
return _PLAYSTATE_CACHE
|
return _PLAYSTATE_CACHE
|
||||||
path = _playstate_path()
|
path = _playstate_path()
|
||||||
@@ -326,7 +269,6 @@ def _load_playstate() -> dict[str, dict[str, object]]:
|
|||||||
|
|
||||||
def _save_playstate(state: dict[str, dict[str, object]]) -> None:
|
def _save_playstate(state: dict[str, dict[str, object]]) -> None:
|
||||||
global _PLAYSTATE_CACHE
|
global _PLAYSTATE_CACHE
|
||||||
with _PLAYSTATE_LOCK:
|
|
||||||
_PLAYSTATE_CACHE = state
|
_PLAYSTATE_CACHE = state
|
||||||
path = _playstate_path()
|
path = _playstate_path()
|
||||||
try:
|
try:
|
||||||
@@ -510,18 +452,40 @@ def _get_setting_int(setting_id: str, *, default: int = 0) -> int:
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
METADATA_MODE_AUTO = 0
|
||||||
|
METADATA_MODE_SOURCE = 1
|
||||||
|
METADATA_MODE_TMDB = 2
|
||||||
|
METADATA_MODE_MIX = 3
|
||||||
|
|
||||||
|
|
||||||
|
def _metadata_setting_id(plugin_name: str) -> str:
|
||||||
|
safe = re.sub(r"[^a-z0-9]+", "_", (plugin_name or "").strip().casefold()).strip("_")
|
||||||
|
return f"{safe}_metadata_source" if safe else "metadata_source"
|
||||||
|
|
||||||
|
|
||||||
|
def _plugin_supports_metadata(plugin: BasisPlugin) -> bool:
|
||||||
|
try:
|
||||||
|
return plugin.__class__.metadata_for is not BasisPlugin.metadata_for
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _metadata_policy(
|
def _metadata_policy(
|
||||||
plugin_name: str,
|
plugin_name: str,
|
||||||
plugin: BasisPlugin,
|
plugin: BasisPlugin,
|
||||||
*,
|
*,
|
||||||
allow_tmdb: bool,
|
allow_tmdb: bool,
|
||||||
) -> tuple[bool, bool, bool]:
|
) -> tuple[bool, bool, bool]:
|
||||||
return _metadata_policy_impl(
|
mode = _get_setting_int(_metadata_setting_id(plugin_name), default=METADATA_MODE_AUTO)
|
||||||
plugin_name,
|
supports_source = _plugin_supports_metadata(plugin)
|
||||||
plugin,
|
if mode == METADATA_MODE_SOURCE:
|
||||||
allow_tmdb=allow_tmdb,
|
return supports_source, False, True
|
||||||
get_setting_int=_get_setting_int,
|
if mode == METADATA_MODE_TMDB:
|
||||||
)
|
return False, allow_tmdb, False
|
||||||
|
if mode == METADATA_MODE_MIX:
|
||||||
|
return supports_source, allow_tmdb, True
|
||||||
|
prefer_source = bool(getattr(plugin, "prefer_source_metadata", False))
|
||||||
|
return supports_source, allow_tmdb, prefer_source
|
||||||
|
|
||||||
|
|
||||||
def _tmdb_list_enabled() -> bool:
|
def _tmdb_list_enabled() -> bool:
|
||||||
@@ -751,11 +715,11 @@ def _tmdb_labels_and_art(title: str) -> tuple[dict[str, str], dict[str, str], li
|
|||||||
show_cast = _get_setting_bool("tmdb_show_cast", default=False)
|
show_cast = _get_setting_bool("tmdb_show_cast", default=False)
|
||||||
flags = f"p{int(show_plot)}a{int(show_art)}f{int(show_fanart)}r{int(show_rating)}v{int(show_votes)}c{int(show_cast)}"
|
flags = f"p{int(show_plot)}a{int(show_art)}f{int(show_fanart)}r{int(show_rating)}v{int(show_votes)}c{int(show_cast)}"
|
||||||
cache_key = f"{language}|{flags}|{title_key}"
|
cache_key = f"{language}|{flags}|{title_key}"
|
||||||
cached = _tmdb_cache_get(_TMDB_CACHE, cache_key)
|
cached = _TMDB_CACHE.get(cache_key)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
info, art = cached
|
info, art = cached
|
||||||
# Cast wird nicht in _TMDB_CACHE gehalten (weil es ListItem.setCast betrifft), daher separat cachen:
|
# Cast wird nicht in _TMDB_CACHE gehalten (weil es ListItem.setCast betrifft), daher separat cachen:
|
||||||
cast_cached = _tmdb_cache_get(_TMDB_CAST_CACHE, cache_key, [])
|
cast_cached = _TMDB_CAST_CACHE.get(cache_key, [])
|
||||||
return info, art, list(cast_cached)
|
return info, art, list(cast_cached)
|
||||||
|
|
||||||
info_labels: dict[str, str] = {"title": title}
|
info_labels: dict[str, str] = {"title": title}
|
||||||
@@ -813,7 +777,7 @@ def _tmdb_labels_and_art(title: str) -> tuple[dict[str, str], dict[str, str], li
|
|||||||
if meta:
|
if meta:
|
||||||
# Nur TV-IDs cachen (für Staffel-/Episoden-Lookups); Movie-IDs würden dort fehlschlagen.
|
# Nur TV-IDs cachen (für Staffel-/Episoden-Lookups); Movie-IDs würden dort fehlschlagen.
|
||||||
if is_tv:
|
if is_tv:
|
||||||
_tmdb_cache_set(_TMDB_ID_CACHE, title_key, int(getattr(meta, "tmdb_id", 0) or 0))
|
_TMDB_ID_CACHE[title_key] = int(getattr(meta, "tmdb_id", 0) or 0)
|
||||||
info_labels.setdefault("mediatype", "tvshow")
|
info_labels.setdefault("mediatype", "tvshow")
|
||||||
else:
|
else:
|
||||||
info_labels.setdefault("mediatype", "movie")
|
info_labels.setdefault("mediatype", "movie")
|
||||||
@@ -841,8 +805,8 @@ def _tmdb_labels_and_art(title: str) -> tuple[dict[str, str], dict[str, str], li
|
|||||||
elif log_requests or log_responses:
|
elif log_requests or log_responses:
|
||||||
_tmdb_file_log(f"TMDB MISS title={title!r}")
|
_tmdb_file_log(f"TMDB MISS title={title!r}")
|
||||||
|
|
||||||
_tmdb_cache_set(_TMDB_CACHE, cache_key, (info_labels, art))
|
_TMDB_CACHE[cache_key] = (info_labels, art)
|
||||||
_tmdb_cache_set(_TMDB_CAST_CACHE, cache_key, list(cast))
|
_TMDB_CAST_CACHE[cache_key] = list(cast)
|
||||||
return info_labels, art, list(cast)
|
return info_labels, art, list(cast)
|
||||||
|
|
||||||
|
|
||||||
@@ -888,10 +852,10 @@ def _tmdb_episode_labels_and_art(*, title: str, season_label: str, episode_label
|
|||||||
if not _tmdb_enabled():
|
if not _tmdb_enabled():
|
||||||
return {"title": episode_label}, {}
|
return {"title": episode_label}, {}
|
||||||
title_key = (title or "").strip().casefold()
|
title_key = (title or "").strip().casefold()
|
||||||
tmdb_id = _tmdb_cache_get(_TMDB_ID_CACHE, title_key)
|
tmdb_id = _TMDB_ID_CACHE.get(title_key)
|
||||||
if not tmdb_id:
|
if not tmdb_id:
|
||||||
_tmdb_labels_and_art(title)
|
_tmdb_labels_and_art(title)
|
||||||
tmdb_id = _tmdb_cache_get(_TMDB_ID_CACHE, title_key)
|
tmdb_id = _TMDB_ID_CACHE.get(title_key)
|
||||||
if not tmdb_id:
|
if not tmdb_id:
|
||||||
return {"title": episode_label}, {}
|
return {"title": episode_label}, {}
|
||||||
|
|
||||||
@@ -905,7 +869,7 @@ def _tmdb_episode_labels_and_art(*, title: str, season_label: str, episode_label
|
|||||||
show_art = _get_setting_bool("tmdb_show_art", default=True)
|
show_art = _get_setting_bool("tmdb_show_art", default=True)
|
||||||
flags = f"p{int(show_plot)}a{int(show_art)}"
|
flags = f"p{int(show_plot)}a{int(show_art)}"
|
||||||
season_key = (tmdb_id, season_number, language, flags)
|
season_key = (tmdb_id, season_number, language, flags)
|
||||||
cached_season = _tmdb_cache_get(_TMDB_SEASON_CACHE, season_key)
|
cached_season = _TMDB_SEASON_CACHE.get(season_key)
|
||||||
if cached_season is None:
|
if cached_season is None:
|
||||||
api_key = _get_setting_string("tmdb_api_key").strip()
|
api_key = _get_setting_string("tmdb_api_key").strip()
|
||||||
if not api_key:
|
if not api_key:
|
||||||
@@ -938,7 +902,7 @@ def _tmdb_episode_labels_and_art(*, title: str, season_label: str, episode_label
|
|||||||
if show_art and ep.thumb:
|
if show_art and ep.thumb:
|
||||||
art = {"thumb": ep.thumb}
|
art = {"thumb": ep.thumb}
|
||||||
mapped[ep_no] = (info, art)
|
mapped[ep_no] = (info, art)
|
||||||
_tmdb_cache_set(_TMDB_SEASON_CACHE, season_key, mapped)
|
_TMDB_SEASON_CACHE[season_key] = mapped
|
||||||
cached_season = mapped
|
cached_season = mapped
|
||||||
|
|
||||||
return cached_season.get(episode_number, ({"title": episode_label}, {}))
|
return cached_season.get(episode_number, ({"title": episode_label}, {}))
|
||||||
@@ -952,10 +916,10 @@ def _tmdb_episode_cast(*, title: str, season_label: str, episode_label: str) ->
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
title_key = (title or "").strip().casefold()
|
title_key = (title or "").strip().casefold()
|
||||||
tmdb_id = _tmdb_cache_get(_TMDB_ID_CACHE, title_key)
|
tmdb_id = _TMDB_ID_CACHE.get(title_key)
|
||||||
if not tmdb_id:
|
if not tmdb_id:
|
||||||
_tmdb_labels_and_art(title)
|
_tmdb_labels_and_art(title)
|
||||||
tmdb_id = _tmdb_cache_get(_TMDB_ID_CACHE, title_key)
|
tmdb_id = _TMDB_ID_CACHE.get(title_key)
|
||||||
if not tmdb_id:
|
if not tmdb_id:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -966,13 +930,13 @@ def _tmdb_episode_cast(*, title: str, season_label: str, episode_label: str) ->
|
|||||||
|
|
||||||
language = _get_setting_string("tmdb_language").strip() or "de-DE"
|
language = _get_setting_string("tmdb_language").strip() or "de-DE"
|
||||||
cache_key = (tmdb_id, season_number, episode_number, language)
|
cache_key = (tmdb_id, season_number, episode_number, language)
|
||||||
cached = _tmdb_cache_get(_TMDB_EPISODE_CAST_CACHE, cache_key)
|
cached = _TMDB_EPISODE_CAST_CACHE.get(cache_key)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return list(cached)
|
return list(cached)
|
||||||
|
|
||||||
api_key = _get_setting_string("tmdb_api_key").strip()
|
api_key = _get_setting_string("tmdb_api_key").strip()
|
||||||
if not api_key:
|
if not api_key:
|
||||||
_tmdb_cache_set(_TMDB_EPISODE_CAST_CACHE, cache_key, [])
|
_TMDB_EPISODE_CAST_CACHE[cache_key] = []
|
||||||
return []
|
return []
|
||||||
|
|
||||||
log_requests = _get_setting_bool("tmdb_log_requests", default=False)
|
log_requests = _get_setting_bool("tmdb_log_requests", default=False)
|
||||||
@@ -994,7 +958,7 @@ def _tmdb_episode_cast(*, title: str, season_label: str, episode_label: str) ->
|
|||||||
f"TMDB ERROR episode_credits_failed tmdb_id={tmdb_id} season={season_number} episode={episode_number} error={exc!r}"
|
f"TMDB ERROR episode_credits_failed tmdb_id={tmdb_id} season={season_number} episode={episode_number} error={exc!r}"
|
||||||
)
|
)
|
||||||
cast = []
|
cast = []
|
||||||
_tmdb_cache_set(_TMDB_EPISODE_CAST_CACHE, cache_key, list(cast))
|
_TMDB_EPISODE_CAST_CACHE[cache_key] = list(cast)
|
||||||
return list(cast)
|
return list(cast)
|
||||||
|
|
||||||
|
|
||||||
@@ -1047,6 +1011,32 @@ def _normalize_update_info_url(raw: str) -> str:
|
|||||||
return value.rstrip("/") + "/addons.xml"
|
return value.rstrip("/") + "/addons.xml"
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE_CHANNEL_MAIN = 0
|
||||||
|
UPDATE_CHANNEL_NIGHTLY = 1
|
||||||
|
UPDATE_CHANNEL_CUSTOM = 2
|
||||||
|
|
||||||
|
|
||||||
|
def _selected_update_channel() -> int:
|
||||||
|
channel = _get_setting_int("update_channel", default=UPDATE_CHANNEL_MAIN)
|
||||||
|
if channel not in {UPDATE_CHANNEL_MAIN, UPDATE_CHANNEL_NIGHTLY, UPDATE_CHANNEL_CUSTOM}:
|
||||||
|
return UPDATE_CHANNEL_MAIN
|
||||||
|
return channel
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_update_info_url() -> str:
|
||||||
|
channel = _selected_update_channel()
|
||||||
|
if channel == UPDATE_CHANNEL_NIGHTLY:
|
||||||
|
raw = _get_setting_string("update_repo_url_nightly")
|
||||||
|
elif channel == UPDATE_CHANNEL_CUSTOM:
|
||||||
|
raw = _get_setting_string("update_repo_url")
|
||||||
|
else:
|
||||||
|
raw = _get_setting_string("update_repo_url_main")
|
||||||
|
info_url = _normalize_update_info_url(raw)
|
||||||
|
# Legacy-Setting beibehalten, damit bestehende Installationen und alte Builds weiterlaufen.
|
||||||
|
_set_setting_string("update_repo_url", info_url)
|
||||||
|
return info_url
|
||||||
|
|
||||||
|
|
||||||
def _repo_addon_xml_path() -> str:
|
def _repo_addon_xml_path() -> str:
|
||||||
if xbmcvfs is None:
|
if xbmcvfs is None:
|
||||||
return ""
|
return ""
|
||||||
@@ -1089,6 +1079,52 @@ def _settings_key_for_plugin(name: str) -> str:
|
|||||||
return f"update_version_{safe}" if safe else "update_version_unknown"
|
return f"update_version_{safe}" if safe else "update_version_unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def _collect_plugin_metadata(plugin: BasisPlugin, titles: list[str]) -> dict[str, tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None]]:
|
||||||
|
getter = getattr(plugin, "metadata_for", None)
|
||||||
|
if not callable(getter):
|
||||||
|
return {}
|
||||||
|
collected: dict[str, tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None]] = {}
|
||||||
|
for title in titles:
|
||||||
|
try:
|
||||||
|
labels, art, cast = getter(title)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
if isinstance(labels, dict) or isinstance(art, dict) or cast:
|
||||||
|
label_map = {str(k): str(v) for k, v in dict(labels or {}).items() if v}
|
||||||
|
art_map = {str(k): str(v) for k, v in dict(art or {}).items() if v}
|
||||||
|
collected[title] = (label_map, art_map, cast if isinstance(cast, list) else None)
|
||||||
|
return collected
|
||||||
|
|
||||||
|
|
||||||
|
def _needs_tmdb(labels: dict[str, str], art: dict[str, str], *, want_plot: bool, want_art: bool) -> bool:
|
||||||
|
if want_plot and not labels.get("plot"):
|
||||||
|
return True
|
||||||
|
if want_art and not (art.get("thumb") or art.get("poster") or art.get("fanart") or art.get("landscape")):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _merge_metadata(
|
||||||
|
title: str,
|
||||||
|
tmdb_labels: dict[str, str] | None,
|
||||||
|
tmdb_art: dict[str, str] | None,
|
||||||
|
tmdb_cast: list[TmdbCastMember] | None,
|
||||||
|
plugin_meta: tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None] | None,
|
||||||
|
) -> tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None]:
|
||||||
|
labels = dict(tmdb_labels or {})
|
||||||
|
art = dict(tmdb_art or {})
|
||||||
|
cast = tmdb_cast
|
||||||
|
if plugin_meta is not None:
|
||||||
|
meta_labels, meta_art, meta_cast = plugin_meta
|
||||||
|
labels.update({k: str(v) for k, v in dict(meta_labels or {}).items() if v})
|
||||||
|
art.update({k: str(v) for k, v in dict(meta_art or {}).items() if v})
|
||||||
|
if meta_cast is not None:
|
||||||
|
cast = meta_cast
|
||||||
|
if "title" not in labels:
|
||||||
|
labels["title"] = title
|
||||||
|
return labels, art, cast
|
||||||
|
|
||||||
|
|
||||||
def _sync_update_version_settings() -> None:
|
def _sync_update_version_settings() -> None:
|
||||||
addon = _get_addon()
|
addon = _get_addon()
|
||||||
addon_version = "0.0.0"
|
addon_version = "0.0.0"
|
||||||
@@ -1200,11 +1236,7 @@ def _show_plugin_search_results(plugin_name: str, query: str) -> None:
|
|||||||
try:
|
try:
|
||||||
with _progress_dialog("Suche laeuft", f"{plugin_name} (1/1) startet...") as progress:
|
with _progress_dialog("Suche laeuft", f"{plugin_name} (1/1) startet...") as progress:
|
||||||
canceled = progress(5, f"{plugin_name} (1/1) Suche...")
|
canceled = progress(5, f"{plugin_name} (1/1) Suche...")
|
||||||
plugin_progress = lambda msg="", pct=None: progress( # noqa: E731 - kompakte Callback-Bruecke
|
search_coro = plugin.search_titles(query)
|
||||||
max(5, min(95, int(pct))) if pct is not None else 20,
|
|
||||||
f"{plugin_name} (1/1) {str(msg or 'Suche...').strip()}",
|
|
||||||
)
|
|
||||||
search_coro = _call_plugin_search(plugin, query, progress_callback=plugin_progress)
|
|
||||||
try:
|
try:
|
||||||
results = _run_async(search_coro)
|
results = _run_async(search_coro)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1438,11 +1470,7 @@ def _show_search_results(query: str) -> None:
|
|||||||
canceled = progress(range_start, f"{plugin_name} ({plugin_index}/{total_plugins}) Suche...")
|
canceled = progress(range_start, f"{plugin_name} ({plugin_index}/{total_plugins}) Suche...")
|
||||||
if canceled:
|
if canceled:
|
||||||
break
|
break
|
||||||
plugin_progress = lambda msg="", pct=None: progress( # noqa: E731 - kompakte Callback-Bruecke
|
search_coro = plugin.search_titles(query)
|
||||||
max(range_start, min(range_end, int(pct))) if pct is not None else range_start + 20,
|
|
||||||
f"{plugin_name} ({plugin_index}/{total_plugins}) {str(msg or 'Suche...').strip()}",
|
|
||||||
)
|
|
||||||
search_coro = _call_plugin_search(plugin, query, progress_callback=plugin_progress)
|
|
||||||
try:
|
try:
|
||||||
results = _run_async(search_coro)
|
results = _run_async(search_coro)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@@ -1616,7 +1644,7 @@ def _show_seasons(plugin_name: str, title: str, series_url: str = "") -> None:
|
|||||||
meta_getter = getattr(plugin, "metadata_for", None)
|
meta_getter = getattr(plugin, "metadata_for", None)
|
||||||
if use_source and callable(meta_getter):
|
if use_source and callable(meta_getter):
|
||||||
try:
|
try:
|
||||||
with _busy_dialog("Metadaten werden geladen..."):
|
with _busy_dialog():
|
||||||
meta_labels, meta_art, meta_cast = meta_getter(title)
|
meta_labels, meta_art, meta_cast = meta_getter(title)
|
||||||
if isinstance(meta_labels, dict):
|
if isinstance(meta_labels, dict):
|
||||||
title_info_labels = {str(k): str(v) for k, v in meta_labels.items() if v}
|
title_info_labels = {str(k): str(v) for k, v in meta_labels.items() if v}
|
||||||
@@ -1656,8 +1684,8 @@ def _show_seasons(plugin_name: str, title: str, series_url: str = "") -> None:
|
|||||||
art: dict[str, str] | None = None
|
art: dict[str, str] | None = None
|
||||||
season_number = _extract_first_int(season)
|
season_number = _extract_first_int(season)
|
||||||
if api_key and season_number is not None:
|
if api_key and season_number is not None:
|
||||||
cache_key = (_tmdb_cache_get(_TMDB_ID_CACHE, (title or "").strip().casefold(), 0), season_number, language, flags)
|
cache_key = (_TMDB_ID_CACHE.get((title or "").strip().casefold(), 0), season_number, language, flags)
|
||||||
cached = _tmdb_cache_get(_TMDB_SEASON_SUMMARY_CACHE, cache_key)
|
cached = _TMDB_SEASON_SUMMARY_CACHE.get(cache_key)
|
||||||
if cached is None and cache_key[0]:
|
if cached is None and cache_key[0]:
|
||||||
try:
|
try:
|
||||||
meta = lookup_tv_season_summary(
|
meta = lookup_tv_season_summary(
|
||||||
@@ -1680,7 +1708,7 @@ def _show_seasons(plugin_name: str, title: str, series_url: str = "") -> None:
|
|||||||
if show_art and meta.poster:
|
if show_art and meta.poster:
|
||||||
art_map = {"thumb": meta.poster, "poster": meta.poster}
|
art_map = {"thumb": meta.poster, "poster": meta.poster}
|
||||||
cached = (labels, art_map)
|
cached = (labels, art_map)
|
||||||
_tmdb_cache_set(_TMDB_SEASON_SUMMARY_CACHE, cache_key, cached)
|
_TMDB_SEASON_SUMMARY_CACHE[cache_key] = cached
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
info_labels, art = cached
|
info_labels, art = cached
|
||||||
merged_labels = dict(info_labels or {})
|
merged_labels = dict(info_labels or {})
|
||||||
@@ -1746,7 +1774,7 @@ def _show_episodes(plugin_name: str, title: str, season: str, series_url: str =
|
|||||||
meta_getter = getattr(plugin, "metadata_for", None)
|
meta_getter = getattr(plugin, "metadata_for", None)
|
||||||
if callable(meta_getter):
|
if callable(meta_getter):
|
||||||
try:
|
try:
|
||||||
with _busy_dialog("Episoden-Metadaten werden geladen..."):
|
with _busy_dialog():
|
||||||
meta_labels, meta_art, meta_cast = meta_getter(title)
|
meta_labels, meta_art, meta_cast = meta_getter(title)
|
||||||
if isinstance(meta_labels, dict):
|
if isinstance(meta_labels, dict):
|
||||||
show_info = {str(k): str(v) for k, v in meta_labels.items() if v}
|
show_info = {str(k): str(v) for k, v in meta_labels.items() if v}
|
||||||
@@ -1759,7 +1787,7 @@ def _show_episodes(plugin_name: str, title: str, season: str, series_url: str =
|
|||||||
|
|
||||||
show_fanart = (show_art or {}).get("fanart") if isinstance(show_art, dict) else ""
|
show_fanart = (show_art or {}).get("fanart") if isinstance(show_art, dict) else ""
|
||||||
show_poster = (show_art or {}).get("poster") if isinstance(show_art, dict) else ""
|
show_poster = (show_art or {}).get("poster") if isinstance(show_art, dict) else ""
|
||||||
with _busy_dialog("Episoden werden aufbereitet..."):
|
with _busy_dialog():
|
||||||
for episode in episodes:
|
for episode in episodes:
|
||||||
if show_tmdb:
|
if show_tmdb:
|
||||||
info_labels, art = _tmdb_episode_labels_and_art(
|
info_labels, art = _tmdb_episode_labels_and_art(
|
||||||
@@ -1990,7 +2018,7 @@ def _show_category_titles_page(plugin_name: str, category: str, page: int = 1) -
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("Genre-Liste wird geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in titles:
|
for title in titles:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -2106,7 +2134,7 @@ def _show_genre_titles_page(plugin_name: str, genre: str, page: int = 1) -> None
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("Genre-Seite wird geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in titles:
|
for title in titles:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -2257,7 +2285,7 @@ def _show_alpha_titles_page(plugin_name: str, letter: str, page: int = 1) -> Non
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("A-Z Liste wird geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in titles:
|
for title in titles:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -2369,7 +2397,7 @@ def _show_series_catalog(plugin_name: str, page: int = 1) -> None:
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("A-Z Seite wird geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in titles:
|
for title in titles:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -2604,7 +2632,7 @@ def _show_popular(plugin_name: str | None = None, page: int = 1) -> None:
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("Beliebte Titel werden geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in page_items:
|
for title in page_items:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -2752,7 +2780,7 @@ def _show_new_titles(plugin_name: str, page: int = 1) -> None:
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("Neue Titel werden geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in page_items:
|
for title in page_items:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -2818,7 +2846,7 @@ def _show_latest_episodes(plugin_name: str, page: int = 1) -> None:
|
|||||||
_set_content(handle, "episodes")
|
_set_content(handle, "episodes")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with _busy_dialog("Neueste Episoden werden geladen..."):
|
with _busy_dialog():
|
||||||
entries = list(getter(page) or [])
|
entries = list(getter(page) or [])
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log(f"Neueste Folgen fehlgeschlagen ({plugin_name}): {exc}", xbmc.LOGWARNING)
|
_log(f"Neueste Folgen fehlgeschlagen ({plugin_name}): {exc}", xbmc.LOGWARNING)
|
||||||
@@ -2923,7 +2951,7 @@ def _show_genre_series_group(plugin_name: str, genre: str, group_code: str, page
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("Genre-Gruppe wird geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in page_items:
|
for title in page_items:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -3011,7 +3039,7 @@ def _show_genre_series_group(plugin_name: str, genre: str, group_code: str, page
|
|||||||
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
if _needs_tmdb(meta_labels, meta_art, want_plot=show_plot, want_art=show_art):
|
||||||
tmdb_titles.append(title)
|
tmdb_titles.append(title)
|
||||||
if show_tmdb and tmdb_titles:
|
if show_tmdb and tmdb_titles:
|
||||||
with _busy_dialog("Genre-Serien werden geladen..."):
|
with _busy_dialog():
|
||||||
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
tmdb_prefetched = _tmdb_labels_and_art_bulk(tmdb_titles)
|
||||||
for title in page_items:
|
for title in page_items:
|
||||||
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
tmdb_info, tmdb_art, tmdb_cast = tmdb_prefetched.get(title, ({}, {}, [])) if show_tmdb else ({}, {}, [])
|
||||||
@@ -3060,8 +3088,7 @@ def _run_update_check() -> None:
|
|||||||
if xbmc is None: # pragma: no cover - outside Kodi
|
if xbmc is None: # pragma: no cover - outside Kodi
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
info_url = _normalize_update_info_url(_get_setting_string("update_repo_url"))
|
info_url = _resolve_update_info_url()
|
||||||
_set_setting_string("update_repo_url", info_url)
|
|
||||||
_sync_update_version_settings()
|
_sync_update_version_settings()
|
||||||
_update_repository_source(info_url)
|
_update_repository_source(info_url)
|
||||||
builtin = getattr(xbmc, "executebuiltin", None)
|
builtin = getattr(xbmc, "executebuiltin", None)
|
||||||
@@ -3254,7 +3281,7 @@ def _play_episode(
|
|||||||
hoster_getter = getattr(plugin, "available_hosters_for", None)
|
hoster_getter = getattr(plugin, "available_hosters_for", None)
|
||||||
if callable(hoster_getter):
|
if callable(hoster_getter):
|
||||||
try:
|
try:
|
||||||
with _busy_dialog("Hoster werden geladen..."):
|
with _busy_dialog():
|
||||||
available_hosters = list(hoster_getter(title, season, episode) or [])
|
available_hosters = list(hoster_getter(title, season, episode) or [])
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log(f"Hoster laden fehlgeschlagen ({plugin_name}): {exc}", xbmc.LOGWARNING)
|
_log(f"Hoster laden fehlgeschlagen ({plugin_name}): {exc}", xbmc.LOGWARNING)
|
||||||
@@ -3338,7 +3365,7 @@ def _play_episode_url(
|
|||||||
hoster_getter = getattr(plugin, "available_hosters_for_url", None)
|
hoster_getter = getattr(plugin, "available_hosters_for_url", None)
|
||||||
if callable(hoster_getter):
|
if callable(hoster_getter):
|
||||||
try:
|
try:
|
||||||
with _busy_dialog("Hoster werden geladen..."):
|
with _busy_dialog():
|
||||||
available_hosters = list(hoster_getter(episode_url) or [])
|
available_hosters = list(hoster_getter(episode_url) or [])
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log(f"Hoster laden fehlgeschlagen ({plugin_name}): {exc}", xbmc.LOGWARNING)
|
_log(f"Hoster laden fehlgeschlagen ({plugin_name}): {exc}", xbmc.LOGWARNING)
|
||||||
|
|||||||
@@ -32,12 +32,3 @@ def get_requests_session(key: str, *, headers: Optional[dict[str, str]] = None):
|
|||||||
pass
|
pass
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
def close_all_sessions() -> None:
|
|
||||||
"""Close and clear all pooled sessions."""
|
|
||||||
for session in list(_SESSIONS.values()):
|
|
||||||
try:
|
|
||||||
session.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
_SESSIONS.clear()
|
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from plugin_interface import BasisPlugin
|
|
||||||
from tmdb import TmdbCastMember
|
|
||||||
|
|
||||||
METADATA_MODE_AUTO = 0
|
|
||||||
METADATA_MODE_SOURCE = 1
|
|
||||||
METADATA_MODE_TMDB = 2
|
|
||||||
METADATA_MODE_MIX = 3
|
|
||||||
|
|
||||||
|
|
||||||
def metadata_setting_id(plugin_name: str) -> str:
|
|
||||||
safe = re.sub(r"[^a-z0-9]+", "_", (plugin_name or "").strip().casefold()).strip("_")
|
|
||||||
return f"{safe}_metadata_source" if safe else "metadata_source"
|
|
||||||
|
|
||||||
|
|
||||||
def plugin_supports_metadata(plugin: BasisPlugin) -> bool:
|
|
||||||
try:
|
|
||||||
return plugin.__class__.metadata_for is not BasisPlugin.metadata_for
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def metadata_policy(
|
|
||||||
plugin_name: str,
|
|
||||||
plugin: BasisPlugin,
|
|
||||||
*,
|
|
||||||
allow_tmdb: bool,
|
|
||||||
get_setting_int=None,
|
|
||||||
) -> tuple[bool, bool, bool]:
|
|
||||||
if not callable(get_setting_int):
|
|
||||||
return plugin_supports_metadata(plugin), allow_tmdb, bool(getattr(plugin, "prefer_source_metadata", False))
|
|
||||||
mode = get_setting_int(metadata_setting_id(plugin_name), default=METADATA_MODE_AUTO)
|
|
||||||
supports_source = plugin_supports_metadata(plugin)
|
|
||||||
if mode == METADATA_MODE_SOURCE:
|
|
||||||
return supports_source, False, True
|
|
||||||
if mode == METADATA_MODE_TMDB:
|
|
||||||
return False, allow_tmdb, False
|
|
||||||
if mode == METADATA_MODE_MIX:
|
|
||||||
return supports_source, allow_tmdb, True
|
|
||||||
prefer_source = bool(getattr(plugin, "prefer_source_metadata", False))
|
|
||||||
return supports_source, allow_tmdb, prefer_source
|
|
||||||
|
|
||||||
|
|
||||||
def collect_plugin_metadata(
|
|
||||||
plugin: BasisPlugin,
|
|
||||||
titles: list[str],
|
|
||||||
) -> dict[str, tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None]]:
|
|
||||||
getter = getattr(plugin, "metadata_for", None)
|
|
||||||
if not callable(getter):
|
|
||||||
return {}
|
|
||||||
collected: dict[str, tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None]] = {}
|
|
||||||
for title in titles:
|
|
||||||
try:
|
|
||||||
labels, art, cast = getter(title)
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
if isinstance(labels, dict) or isinstance(art, dict) or cast:
|
|
||||||
label_map = {str(k): str(v) for k, v in dict(labels or {}).items() if v}
|
|
||||||
art_map = {str(k): str(v) for k, v in dict(art or {}).items() if v}
|
|
||||||
collected[title] = (label_map, art_map, cast if isinstance(cast, list) else None)
|
|
||||||
return collected
|
|
||||||
|
|
||||||
|
|
||||||
def needs_tmdb(labels: dict[str, str], art: dict[str, str], *, want_plot: bool, want_art: bool) -> bool:
|
|
||||||
if want_plot and not labels.get("plot"):
|
|
||||||
return True
|
|
||||||
if want_art and not (art.get("thumb") or art.get("poster") or art.get("fanart") or art.get("landscape")):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def merge_metadata(
|
|
||||||
title: str,
|
|
||||||
tmdb_labels: dict[str, str] | None,
|
|
||||||
tmdb_art: dict[str, str] | None,
|
|
||||||
tmdb_cast: list[TmdbCastMember] | None,
|
|
||||||
plugin_meta: tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None] | None,
|
|
||||||
) -> tuple[dict[str, str], dict[str, str], list[TmdbCastMember] | None]:
|
|
||||||
labels = dict(tmdb_labels or {})
|
|
||||||
art = dict(tmdb_art or {})
|
|
||||||
cast = tmdb_cast
|
|
||||||
if plugin_meta is not None:
|
|
||||||
meta_labels, meta_art, meta_cast = plugin_meta
|
|
||||||
labels.update({k: str(v) for k, v in dict(meta_labels or {}).items() if v})
|
|
||||||
art.update({k: str(v) for k, v in dict(meta_art or {}).items() if v})
|
|
||||||
if meta_cast is not None:
|
|
||||||
cast = meta_cast
|
|
||||||
if "title" not in labels:
|
|
||||||
labels["title"] = title
|
|
||||||
return labels, art, cast
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple
|
from typing import Any, Dict, List, Optional, Set, Tuple
|
||||||
|
|
||||||
|
|
||||||
class BasisPlugin(ABC):
|
class BasisPlugin(ABC):
|
||||||
@@ -15,11 +15,7 @@ class BasisPlugin(ABC):
|
|||||||
prefer_source_metadata: bool = False
|
prefer_source_metadata: bool = False
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def search_titles(
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
self,
|
|
||||||
query: str,
|
|
||||||
progress_callback: Optional[Callable[[str, Optional[int]], Any]] = None,
|
|
||||||
) -> List[str]:
|
|
||||||
"""Liefert eine Liste aller Treffer fuer die Suche."""
|
"""Liefert eine Liste aller Treffer fuer die Suche."""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Zum Verwenden:
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Any, Callable, List, Optional
|
from typing import TYPE_CHECKING, Any, List, Optional
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency
|
try: # pragma: no cover - optional dependency
|
||||||
import requests
|
import requests
|
||||||
@@ -88,13 +88,9 @@ class TemplatePlugin(BasisPlugin):
|
|||||||
self._session = session
|
self._session = session
|
||||||
return self._session
|
return self._session
|
||||||
|
|
||||||
async def search_titles(
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
self,
|
|
||||||
query: str,
|
|
||||||
progress_callback: Optional[Callable[[str, Optional[int]], Any]] = None,
|
|
||||||
) -> List[str]:
|
|
||||||
"""TODO: Suche auf der Zielseite implementieren."""
|
"""TODO: Suche auf der Zielseite implementieren."""
|
||||||
_ = (query, progress_callback)
|
_ = query
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def seasons_for(self, title: str) -> List[str]:
|
def seasons_for(self, title: str) -> List[str]:
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
|
||||||
from urllib.parse import quote
|
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency
|
try: # pragma: no cover - optional dependency
|
||||||
import requests
|
import requests
|
||||||
@@ -70,16 +69,6 @@ HEADERS = {
|
|||||||
SESSION_CACHE_TTL_SECONDS = 300
|
SESSION_CACHE_TTL_SECONDS = 300
|
||||||
SESSION_CACHE_PREFIX = "viewit.aniworld"
|
SESSION_CACHE_PREFIX = "viewit.aniworld"
|
||||||
SESSION_CACHE_MAX_TITLE_URLS = 800
|
SESSION_CACHE_MAX_TITLE_URLS = 800
|
||||||
ProgressCallback = Optional[Callable[[str, Optional[int]], Any]]
|
|
||||||
|
|
||||||
|
|
||||||
def _emit_progress(callback: ProgressCallback, message: str, percent: Optional[int] = None) -> None:
|
|
||||||
if not callable(callback):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
callback(str(message or ""), None if percent is None else int(percent))
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -137,7 +126,7 @@ def _latest_episodes_url() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _search_url(query: str) -> str:
|
def _search_url(query: str) -> str:
|
||||||
return f"{_get_base_url()}/search?q={quote((query or '').strip())}"
|
return f"{_get_base_url()}/search?q={query}"
|
||||||
|
|
||||||
|
|
||||||
def _search_api_url() -> str:
|
def _search_api_url() -> str:
|
||||||
@@ -300,56 +289,37 @@ def _get_soup(url: str, *, session: Optional[RequestsSession] = None) -> Beautif
|
|||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = session or get_requests_session("aniworld", headers=HEADERS)
|
sess = session or get_requests_session("aniworld", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error(f"GET {url} failed: {exc}")
|
_log_error(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
if response.url and response.url != url:
|
||||||
final_url = (response.url or url) if response is not None else url
|
_log_url(response.url, kind="REDIRECT")
|
||||||
body = (response.text or "") if response is not None else ""
|
_log_response_html(url, response.text)
|
||||||
if final_url != url:
|
if _looks_like_cloudflare_challenge(response.text):
|
||||||
_log_url(final_url, kind="REDIRECT")
|
|
||||||
_log_response_html(url, body)
|
|
||||||
if _looks_like_cloudflare_challenge(body):
|
|
||||||
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
||||||
return BeautifulSoup(body, "html.parser")
|
return BeautifulSoup(response.text, "html.parser")
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_html_simple(url: str) -> str:
|
def _get_html_simple(url: str) -> str:
|
||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = get_requests_session("aniworld", headers=HEADERS)
|
sess = get_requests_session("aniworld", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error(f"GET {url} failed: {exc}")
|
_log_error(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
if response.url and response.url != url:
|
||||||
final_url = (response.url or url) if response is not None else url
|
_log_url(response.url, kind="REDIRECT")
|
||||||
body = (response.text or "") if response is not None else ""
|
body = response.text
|
||||||
if final_url != url:
|
|
||||||
_log_url(final_url, kind="REDIRECT")
|
|
||||||
_log_response_html(url, body)
|
_log_response_html(url, body)
|
||||||
if _looks_like_cloudflare_challenge(body):
|
if _looks_like_cloudflare_challenge(body):
|
||||||
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
||||||
return body
|
return body
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_soup_simple(url: str) -> BeautifulSoupT:
|
def _get_soup_simple(url: str) -> BeautifulSoupT:
|
||||||
@@ -381,27 +351,17 @@ def _post_json(url: str, *, payload: Dict[str, str], session: Optional[RequestsS
|
|||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = session or get_requests_session("aniworld", headers=HEADERS)
|
sess = session or get_requests_session("aniworld", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
|
||||||
response = sess.post(url, data=payload, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.post(url, data=payload, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
final_url = (response.url or url) if response is not None else url
|
if response.url and response.url != url:
|
||||||
body = (response.text or "") if response is not None else ""
|
_log_url(response.url, kind="REDIRECT")
|
||||||
if final_url != url:
|
_log_response_html(url, response.text)
|
||||||
_log_url(final_url, kind="REDIRECT")
|
if _looks_like_cloudflare_challenge(response.text):
|
||||||
_log_response_html(url, body)
|
|
||||||
if _looks_like_cloudflare_challenge(body):
|
|
||||||
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
||||||
try:
|
try:
|
||||||
return response.json()
|
return response.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _extract_canonical_url(soup: BeautifulSoupT, fallback: str) -> str:
|
def _extract_canonical_url(soup: BeautifulSoupT, fallback: str) -> str:
|
||||||
@@ -595,18 +555,10 @@ def resolve_redirect(target_url: str) -> Optional[str]:
|
|||||||
_log_visit(normalized_url)
|
_log_visit(normalized_url)
|
||||||
session = get_requests_session("aniworld", headers=HEADERS)
|
session = get_requests_session("aniworld", headers=HEADERS)
|
||||||
_get_soup(_get_base_url(), session=session)
|
_get_soup(_get_base_url(), session=session)
|
||||||
response = None
|
|
||||||
try:
|
|
||||||
response = session.get(normalized_url, headers=HEADERS, timeout=DEFAULT_TIMEOUT, allow_redirects=True)
|
response = session.get(normalized_url, headers=HEADERS, timeout=DEFAULT_TIMEOUT, allow_redirects=True)
|
||||||
if response.url:
|
if response.url:
|
||||||
_log_url(response.url, kind="RESOLVED")
|
_log_url(response.url, kind="RESOLVED")
|
||||||
return response.url if response.url else None
|
return response.url if response.url else None
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_episode_hoster_names(episode_url: str) -> List[str]:
|
def fetch_episode_hoster_names(episode_url: str) -> List[str]:
|
||||||
@@ -677,12 +629,11 @@ def fetch_episode_stream_link(
|
|||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
|
|
||||||
def search_animes(query: str, *, progress_callback: ProgressCallback = None) -> List[SeriesResult]:
|
def search_animes(query: str) -> List[SeriesResult]:
|
||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
query = (query or "").strip()
|
query = (query or "").strip()
|
||||||
if not query:
|
if not query:
|
||||||
return []
|
return []
|
||||||
_emit_progress(progress_callback, "AniWorld API-Suche", 15)
|
|
||||||
session = get_requests_session("aniworld", headers=HEADERS)
|
session = get_requests_session("aniworld", headers=HEADERS)
|
||||||
try:
|
try:
|
||||||
session.get(_get_base_url(), headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
session.get(_get_base_url(), headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
@@ -692,9 +643,7 @@ def search_animes(query: str, *, progress_callback: ProgressCallback = None) ->
|
|||||||
results: List[SeriesResult] = []
|
results: List[SeriesResult] = []
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
for idx, entry in enumerate(data, start=1):
|
for entry in data:
|
||||||
if idx == 1 or idx % 50 == 0:
|
|
||||||
_emit_progress(progress_callback, f"API auswerten {idx}/{len(data)}", 35)
|
|
||||||
if not isinstance(entry, dict):
|
if not isinstance(entry, dict):
|
||||||
continue
|
continue
|
||||||
title = _strip_html((entry.get("title") or "").strip())
|
title = _strip_html((entry.get("title") or "").strip())
|
||||||
@@ -716,16 +665,10 @@ def search_animes(query: str, *, progress_callback: ProgressCallback = None) ->
|
|||||||
seen.add(key)
|
seen.add(key)
|
||||||
description = (entry.get("description") or "").strip()
|
description = (entry.get("description") or "").strip()
|
||||||
results.append(SeriesResult(title=title, description=description, url=url))
|
results.append(SeriesResult(title=title, description=description, url=url))
|
||||||
_emit_progress(progress_callback, f"API-Treffer: {len(results)}", 85)
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
_emit_progress(progress_callback, "HTML-Suche (Fallback)", 55)
|
soup = _get_soup_simple(_search_url(requests.utils.quote(query)))
|
||||||
soup = _get_soup_simple(_search_url(query))
|
for anchor in soup.select("a[href^='/anime/stream/'][href]"):
|
||||||
anchors = soup.select("a[href^='/anime/stream/'][href]")
|
|
||||||
total_anchors = max(1, len(anchors))
|
|
||||||
for idx, anchor in enumerate(anchors, start=1):
|
|
||||||
if idx == 1 or idx % 100 == 0:
|
|
||||||
_emit_progress(progress_callback, f"HTML auswerten {idx}/{total_anchors}", 70)
|
|
||||||
href = (anchor.get("href") or "").strip()
|
href = (anchor.get("href") or "").strip()
|
||||||
if not href or "/staffel-" in href or "/episode-" in href:
|
if not href or "/staffel-" in href or "/episode-" in href:
|
||||||
continue
|
continue
|
||||||
@@ -743,7 +686,6 @@ def search_animes(query: str, *, progress_callback: ProgressCallback = None) ->
|
|||||||
continue
|
continue
|
||||||
seen.add(key)
|
seen.add(key)
|
||||||
results.append(SeriesResult(title=title, description="", url=url))
|
results.append(SeriesResult(title=title, description="", url=url))
|
||||||
_emit_progress(progress_callback, f"HTML-Treffer: {len(results)}", 85)
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
@@ -1209,7 +1151,7 @@ class AniworldPlugin(BasisPlugin):
|
|||||||
return self._episode_label_cache.get(cache_key, {}).get(episode_label)
|
return self._episode_label_cache.get(cache_key, {}).get(episode_label)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def search_titles(self, query: str, progress_callback: ProgressCallback = None) -> List[str]:
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
query = (query or "").strip()
|
query = (query or "").strip()
|
||||||
if not query:
|
if not query:
|
||||||
self._anime_results.clear()
|
self._anime_results.clear()
|
||||||
@@ -1221,8 +1163,7 @@ class AniworldPlugin(BasisPlugin):
|
|||||||
if not self._requests_available:
|
if not self._requests_available:
|
||||||
raise RuntimeError("AniworldPlugin kann ohne requests/bs4 nicht suchen.")
|
raise RuntimeError("AniworldPlugin kann ohne requests/bs4 nicht suchen.")
|
||||||
try:
|
try:
|
||||||
_emit_progress(progress_callback, "AniWorld Suche startet", 10)
|
results = search_animes(query)
|
||||||
results = search_animes(query, progress_callback=progress_callback)
|
|
||||||
except Exception as exc: # pragma: no cover
|
except Exception as exc: # pragma: no cover
|
||||||
self._anime_results.clear()
|
self._anime_results.clear()
|
||||||
self._season_cache.clear()
|
self._season_cache.clear()
|
||||||
@@ -1237,7 +1178,6 @@ class AniworldPlugin(BasisPlugin):
|
|||||||
self._season_cache.clear()
|
self._season_cache.clear()
|
||||||
self._season_links_cache.clear()
|
self._season_links_cache.clear()
|
||||||
self._episode_label_cache.clear()
|
self._episode_label_cache.clear()
|
||||||
_emit_progress(progress_callback, f"Treffer aufbereitet: {len(results)}", 95)
|
|
||||||
return [result.title for result in results]
|
return [result.title for result in results]
|
||||||
|
|
||||||
def _ensure_seasons(self, title: str) -> List[SeasonInfo]:
|
def _ensure_seasons(self, title: str) -> List[SeasonInfo]:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import re
|
import re
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency
|
try: # pragma: no cover - optional dependency
|
||||||
import requests
|
import requests
|
||||||
@@ -44,16 +44,6 @@ SETTING_LOG_URLS = "log_urls_dokustreams"
|
|||||||
SETTING_DUMP_HTML = "dump_html_dokustreams"
|
SETTING_DUMP_HTML = "dump_html_dokustreams"
|
||||||
SETTING_SHOW_URL_INFO = "show_url_info_dokustreams"
|
SETTING_SHOW_URL_INFO = "show_url_info_dokustreams"
|
||||||
SETTING_LOG_ERRORS = "log_errors_dokustreams"
|
SETTING_LOG_ERRORS = "log_errors_dokustreams"
|
||||||
ProgressCallback = Optional[Callable[[str, Optional[int]], Any]]
|
|
||||||
|
|
||||||
|
|
||||||
def _emit_progress(callback: ProgressCallback, message: str, percent: Optional[int] = None) -> None:
|
|
||||||
if not callable(callback):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
callback(str(message or ""), None if percent is None else int(percent))
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
"User-Agent": "Mozilla/5.0 (Kodi; ViewIt) AppleWebKit/537.36 (KHTML, like Gecko)",
|
"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",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||||
@@ -223,26 +213,16 @@ def _get_soup(url: str, *, session: Optional[RequestsSession] = None) -> Beautif
|
|||||||
raise RuntimeError("requests/bs4 sind nicht verfuegbar.")
|
raise RuntimeError("requests/bs4 sind nicht verfuegbar.")
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = session or get_requests_session("dokustreams", headers=HEADERS)
|
sess = session or get_requests_session("dokustreams", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error_message(f"GET {url} failed: {exc}")
|
_log_error_message(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
if response.url and response.url != url:
|
||||||
final_url = (response.url or url) if response is not None else url
|
_log_url_event(response.url, kind="REDIRECT")
|
||||||
body = (response.text or "") if response is not None else ""
|
_log_response_html(url, response.text)
|
||||||
if final_url != url:
|
return BeautifulSoup(response.text, "html.parser")
|
||||||
_log_url_event(final_url, kind="REDIRECT")
|
|
||||||
_log_response_html(url, body)
|
|
||||||
return BeautifulSoup(body, "html.parser")
|
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DokuStreamsPlugin(BasisPlugin):
|
class DokuStreamsPlugin(BasisPlugin):
|
||||||
@@ -267,17 +247,14 @@ class DokuStreamsPlugin(BasisPlugin):
|
|||||||
if REQUESTS_IMPORT_ERROR:
|
if REQUESTS_IMPORT_ERROR:
|
||||||
print(f"DokuStreamsPlugin Importfehler: {REQUESTS_IMPORT_ERROR}")
|
print(f"DokuStreamsPlugin Importfehler: {REQUESTS_IMPORT_ERROR}")
|
||||||
|
|
||||||
async def search_titles(self, query: str, progress_callback: ProgressCallback = None) -> List[str]:
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
_emit_progress(progress_callback, "Doku-Streams Suche", 15)
|
|
||||||
hits = self._search_hits(query)
|
hits = self._search_hits(query)
|
||||||
_emit_progress(progress_callback, f"Treffer verarbeiten ({len(hits)})", 70)
|
|
||||||
self._title_to_url = {hit.title: hit.url for hit in hits if hit.title and hit.url}
|
self._title_to_url = {hit.title: hit.url for hit in hits if hit.title and hit.url}
|
||||||
for hit in hits:
|
for hit in hits:
|
||||||
if hit.title:
|
if hit.title:
|
||||||
self._title_meta[hit.title] = (hit.plot, hit.poster)
|
self._title_meta[hit.title] = (hit.plot, hit.poster)
|
||||||
titles = [hit.title for hit in hits if hit.title]
|
titles = [hit.title for hit in hits if hit.title]
|
||||||
titles.sort(key=lambda value: value.casefold())
|
titles.sort(key=lambda value: value.casefold())
|
||||||
_emit_progress(progress_callback, f"Fertig: {len(titles)} Treffer", 95)
|
|
||||||
return titles
|
return titles
|
||||||
|
|
||||||
def _search_hits(self, query: str) -> List[SearchHit]:
|
def _search_hits(self, query: str) -> List[SearchHit]:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Callable, Dict, List, Optional, Set
|
from typing import Any, Dict, List, Optional, Set
|
||||||
from urllib.parse import urlencode, urljoin, urlsplit
|
from urllib.parse import urlencode, urljoin, urlsplit
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency (Kodi dependency)
|
try: # pragma: no cover - optional dependency (Kodi dependency)
|
||||||
@@ -56,16 +56,6 @@ HEADERS = {
|
|||||||
"Accept-Language": "de-DE,de;q=0.9,en;q=0.8",
|
"Accept-Language": "de-DE,de;q=0.9,en;q=0.8",
|
||||||
"Connection": "keep-alive",
|
"Connection": "keep-alive",
|
||||||
}
|
}
|
||||||
ProgressCallback = Optional[Callable[[str, Optional[int]], Any]]
|
|
||||||
|
|
||||||
|
|
||||||
def _emit_progress(callback: ProgressCallback, message: str, percent: Optional[int] = None) -> None:
|
|
||||||
if not callable(callback):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
callback(str(message or ""), None if percent is None else int(percent))
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
@@ -536,34 +526,6 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
self._session = requests.Session()
|
self._session = requests.Session()
|
||||||
return self._session
|
return self._session
|
||||||
|
|
||||||
def _http_get_text(self, url: str, *, timeout: int = 20) -> tuple[str, str]:
|
|
||||||
_log_url(url, kind="GET")
|
|
||||||
_notify_url(url)
|
|
||||||
sess = self._get_session()
|
|
||||||
response = None
|
|
||||||
try:
|
|
||||||
response = sess.get(url, headers=HEADERS, timeout=timeout)
|
|
||||||
response.raise_for_status()
|
|
||||||
final_url = (response.url or url) if response is not None else url
|
|
||||||
body = (response.text or "") if response is not None else ""
|
|
||||||
_log_url(final_url, kind="OK")
|
|
||||||
_log_response_html(final_url, body)
|
|
||||||
return final_url, body
|
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _http_get_json(self, url: str, *, timeout: int = 20) -> tuple[str, Any]:
|
|
||||||
final_url, body = self._http_get_text(url, timeout=timeout)
|
|
||||||
try:
|
|
||||||
payload = json.loads(body or "{}")
|
|
||||||
except Exception:
|
|
||||||
payload = {}
|
|
||||||
return final_url, payload
|
|
||||||
|
|
||||||
def _get_base_url(self) -> str:
|
def _get_base_url(self) -> str:
|
||||||
base = _get_setting_text(SETTING_BASE_URL, default=DEFAULT_BASE_URL).strip()
|
base = _get_setting_text(SETTING_BASE_URL, default=DEFAULT_BASE_URL).strip()
|
||||||
return base.rstrip("/")
|
return base.rstrip("/")
|
||||||
@@ -684,9 +646,15 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return ""
|
return ""
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
self._detail_html_by_id[movie_id] = body
|
_notify_url(url)
|
||||||
return body
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_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 as exc:
|
except Exception as exc:
|
||||||
_log_error(f"GET {url} failed: {exc}")
|
_log_error(f"GET {url} failed: {exc}")
|
||||||
return ""
|
return ""
|
||||||
@@ -699,8 +667,16 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return {}
|
return {}
|
||||||
try:
|
try:
|
||||||
_, data = self._http_get_json(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
return data
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
# Some backends may return JSON with a JSON content-type; for debugging we still dump text.
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
data = resp.json()
|
||||||
|
return dict(data) if isinstance(data, dict) else {}
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error(f"GET {url} failed: {exc}")
|
_log_error(f"GET {url} failed: {exc}")
|
||||||
return {}
|
return {}
|
||||||
@@ -765,8 +741,14 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
payload = _extract_ng_state_payload(body)
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
payload = _extract_ng_state_payload(resp.text)
|
||||||
return _parse_ng_state_movies(payload)
|
return _parse_ng_state_movies(payload)
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
@@ -777,8 +759,14 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
payload = _extract_ng_state_payload(body)
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
payload = _extract_ng_state_payload(resp.text)
|
||||||
movies = _parse_ng_state_movies(payload)
|
movies = _parse_ng_state_movies(payload)
|
||||||
_log_debug_line(f"parse_ng_state_movies:count={len(movies)}")
|
_log_debug_line(f"parse_ng_state_movies:count={len(movies)}")
|
||||||
if movies:
|
if movies:
|
||||||
@@ -796,8 +784,14 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if page > 1:
|
if page > 1:
|
||||||
url = f"{url}?{urlencode({'page': str(page)})}"
|
url = f"{url}?{urlencode({'page': str(page)})}"
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
payload = _extract_ng_state_payload(body)
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
payload = _extract_ng_state_payload(resp.text)
|
||||||
movies, has_more, current_page = _parse_ng_state_movies_with_pagination(payload)
|
movies, has_more, current_page = _parse_ng_state_movies_with_pagination(payload)
|
||||||
_log_debug_line(f"parse_ng_state_movies_page:page={page} count={len(movies)}")
|
_log_debug_line(f"parse_ng_state_movies_page:page={page} count={len(movies)}")
|
||||||
if has_more is not None:
|
if has_more is not None:
|
||||||
@@ -850,8 +844,14 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
payload = _extract_ng_state_payload(body)
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
payload = _extract_ng_state_payload(resp.text)
|
||||||
results = _parse_ng_state_search_results(payload)
|
results = _parse_ng_state_search_results(payload)
|
||||||
return _filter_movies_by_title(query, results)
|
return _filter_movies_by_title(query, results)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -867,7 +867,13 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
api_url = self._api_genres_url()
|
api_url = self._api_genres_url()
|
||||||
if api_url:
|
if api_url:
|
||||||
try:
|
try:
|
||||||
_, payload = self._http_get_json(api_url, timeout=20)
|
_log_url(api_url, kind="GET")
|
||||||
|
_notify_url(api_url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(api_url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or api_url, kind="OK")
|
||||||
|
payload = resp.json()
|
||||||
if isinstance(payload, list):
|
if isinstance(payload, list):
|
||||||
parsed: Dict[str, int] = {}
|
parsed: Dict[str, int] = {}
|
||||||
for item in payload:
|
for item in payload:
|
||||||
@@ -894,8 +900,14 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
payload = _extract_ng_state_payload(body)
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
payload = _extract_ng_state_payload(resp.text)
|
||||||
parsed = _parse_ng_state_genres(payload)
|
parsed = _parse_ng_state_genres(payload)
|
||||||
if parsed:
|
if parsed:
|
||||||
self._genre_id_by_name.clear()
|
self._genre_id_by_name.clear()
|
||||||
@@ -903,7 +915,7 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
async def search_titles(self, query: str, progress_callback: ProgressCallback = None) -> List[str]:
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
if not REQUESTS_AVAILABLE:
|
if not REQUESTS_AVAILABLE:
|
||||||
return []
|
return []
|
||||||
query = (query or "").strip()
|
query = (query or "").strip()
|
||||||
@@ -912,12 +924,9 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not self._get_base_url():
|
if not self._get_base_url():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
_emit_progress(progress_callback, "Einschalten Suche", 15)
|
|
||||||
movies = self._fetch_search_movies(query)
|
movies = self._fetch_search_movies(query)
|
||||||
if not movies:
|
if not movies:
|
||||||
_emit_progress(progress_callback, "Fallback: Index filtern", 45)
|
|
||||||
movies = _filter_movies_by_title(query, self._load_movies())
|
movies = _filter_movies_by_title(query, self._load_movies())
|
||||||
_emit_progress(progress_callback, f"Treffer verarbeiten ({len(movies)})", 75)
|
|
||||||
titles: List[str] = []
|
titles: List[str] = []
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
for movie in movies:
|
for movie in movies:
|
||||||
@@ -927,7 +936,6 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
self._id_by_title[movie.title] = movie.id
|
self._id_by_title[movie.title] = movie.id
|
||||||
titles.append(movie.title)
|
titles.append(movie.title)
|
||||||
titles.sort(key=lambda value: value.casefold())
|
titles.sort(key=lambda value: value.casefold())
|
||||||
_emit_progress(progress_callback, f"Fertig: {len(titles)} Treffer", 95)
|
|
||||||
return titles
|
return titles
|
||||||
|
|
||||||
def genres(self) -> List[str]:
|
def genres(self) -> List[str]:
|
||||||
@@ -963,8 +971,14 @@ class EinschaltenPlugin(BasisPlugin):
|
|||||||
if not url:
|
if not url:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
_, body = self._http_get_text(url, timeout=20)
|
_log_url(url, kind="GET")
|
||||||
payload = _extract_ng_state_payload(body)
|
_notify_url(url)
|
||||||
|
sess = self._get_session()
|
||||||
|
resp = sess.get(url, headers=HEADERS, timeout=20)
|
||||||
|
resp.raise_for_status()
|
||||||
|
_log_url(resp.url or url, kind="OK")
|
||||||
|
_log_response_html(resp.url or url, resp.text)
|
||||||
|
payload = _extract_ng_state_payload(resp.text)
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
if not isinstance(payload, dict):
|
if not isinstance(payload, dict):
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from dataclasses import dataclass
|
|||||||
import re
|
import re
|
||||||
from urllib.parse import quote, urlencode
|
from urllib.parse import quote, urlencode
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency
|
try: # pragma: no cover - optional dependency
|
||||||
import requests
|
import requests
|
||||||
@@ -53,16 +53,6 @@ SETTING_LOG_URLS = "log_urls_filmpalast"
|
|||||||
SETTING_DUMP_HTML = "dump_html_filmpalast"
|
SETTING_DUMP_HTML = "dump_html_filmpalast"
|
||||||
SETTING_SHOW_URL_INFO = "show_url_info_filmpalast"
|
SETTING_SHOW_URL_INFO = "show_url_info_filmpalast"
|
||||||
SETTING_LOG_ERRORS = "log_errors_filmpalast"
|
SETTING_LOG_ERRORS = "log_errors_filmpalast"
|
||||||
ProgressCallback = Optional[Callable[[str, Optional[int]], Any]]
|
|
||||||
|
|
||||||
|
|
||||||
def _emit_progress(callback: ProgressCallback, message: str, percent: Optional[int] = None) -> None:
|
|
||||||
if not callable(callback):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
callback(str(message or ""), None if percent is None else int(percent))
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
"User-Agent": "Mozilla/5.0 (Kodi; ViewIt) AppleWebKit/537.36 (KHTML, like Gecko)",
|
"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",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||||
@@ -216,26 +206,16 @@ def _get_soup(url: str, *, session: Optional[RequestsSession] = None) -> Beautif
|
|||||||
raise RuntimeError("requests/bs4 sind nicht verfuegbar.")
|
raise RuntimeError("requests/bs4 sind nicht verfuegbar.")
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = session or get_requests_session("filmpalast", headers=HEADERS)
|
sess = session or get_requests_session("filmpalast", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error_message(f"GET {url} failed: {exc}")
|
_log_error_message(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
if response.url and response.url != url:
|
||||||
final_url = (response.url or url) if response is not None else url
|
_log_url_event(response.url, kind="REDIRECT")
|
||||||
body = (response.text or "") if response is not None else ""
|
_log_response_html(url, response.text)
|
||||||
if final_url != url:
|
return BeautifulSoup(response.text, "html.parser")
|
||||||
_log_url_event(final_url, kind="REDIRECT")
|
|
||||||
_log_response_html(url, body)
|
|
||||||
return BeautifulSoup(body, "html.parser")
|
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FilmpalastPlugin(BasisPlugin):
|
class FilmpalastPlugin(BasisPlugin):
|
||||||
@@ -372,7 +352,6 @@ class FilmpalastPlugin(BasisPlugin):
|
|||||||
seen_titles: set[str] = set()
|
seen_titles: set[str] = set()
|
||||||
seen_urls: set[str] = set()
|
seen_urls: set[str] = set()
|
||||||
for base_url, params in search_requests:
|
for base_url, params in search_requests:
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
request_url = base_url if not params else f"{base_url}?{urlencode(params)}"
|
request_url = base_url if not params else f"{base_url}?{urlencode(params)}"
|
||||||
_log_url_event(request_url, kind="GET")
|
_log_url_event(request_url, kind="GET")
|
||||||
@@ -386,12 +365,6 @@ class FilmpalastPlugin(BasisPlugin):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error_message(f"search request failed ({base_url}): {exc}")
|
_log_error_message(f"search request failed ({base_url}): {exc}")
|
||||||
continue
|
continue
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
anchors = soup.select("article.liste h2 a[href], article.liste h3 a[href]")
|
anchors = soup.select("article.liste h2 a[href], article.liste h3 a[href]")
|
||||||
if not anchors:
|
if not anchors:
|
||||||
@@ -493,13 +466,9 @@ class FilmpalastPlugin(BasisPlugin):
|
|||||||
titles.sort(key=lambda value: value.casefold())
|
titles.sort(key=lambda value: value.casefold())
|
||||||
return titles
|
return titles
|
||||||
|
|
||||||
async def search_titles(self, query: str, progress_callback: ProgressCallback = None) -> List[str]:
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
_emit_progress(progress_callback, "Filmpalast Suche", 15)
|
|
||||||
hits = self._search_hits(query)
|
hits = self._search_hits(query)
|
||||||
_emit_progress(progress_callback, f"Treffer verarbeiten ({len(hits)})", 70)
|
return self._apply_hits_to_title_index(hits)
|
||||||
titles = self._apply_hits_to_title_index(hits)
|
|
||||||
_emit_progress(progress_callback, f"Fertig: {len(titles)} Treffer", 95)
|
|
||||||
return titles
|
|
||||||
|
|
||||||
def _parse_genres(self, soup: BeautifulSoupT) -> Dict[str, str]:
|
def _parse_genres(self, soup: BeautifulSoupT) -> Dict[str, str]:
|
||||||
genres: Dict[str, str] = {}
|
genres: Dict[str, str] = {}
|
||||||
@@ -944,7 +913,6 @@ class FilmpalastPlugin(BasisPlugin):
|
|||||||
|
|
||||||
redirected = link
|
redirected = link
|
||||||
if self._requests_available:
|
if self._requests_available:
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
session = get_requests_session("filmpalast", headers=HEADERS)
|
session = get_requests_session("filmpalast", headers=HEADERS)
|
||||||
response = session.get(link, headers=HEADERS, timeout=DEFAULT_TIMEOUT, allow_redirects=True)
|
response = session.get(link, headers=HEADERS, timeout=DEFAULT_TIMEOUT, allow_redirects=True)
|
||||||
@@ -952,12 +920,6 @@ class FilmpalastPlugin(BasisPlugin):
|
|||||||
redirected = (response.url or link).strip() or link
|
redirected = (response.url or link).strip() or link
|
||||||
except Exception:
|
except Exception:
|
||||||
redirected = link
|
redirected = link
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 2) Danach optional die Redirect-URL nochmals auflösen.
|
# 2) Danach optional die Redirect-URL nochmals auflösen.
|
||||||
if callable(resolve_with_resolveurl) and redirected and redirected != link:
|
if callable(resolve_with_resolveurl) and redirected and redirected != link:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency
|
try: # pragma: no cover - optional dependency
|
||||||
@@ -80,16 +80,6 @@ SESSION_CACHE_MAX_TITLE_URLS = 800
|
|||||||
CATALOG_SEARCH_TTL_SECONDS = 600
|
CATALOG_SEARCH_TTL_SECONDS = 600
|
||||||
CATALOG_SEARCH_CACHE_KEY = "catalog_index"
|
CATALOG_SEARCH_CACHE_KEY = "catalog_index"
|
||||||
_CATALOG_INDEX_MEMORY: tuple[float, List["SeriesResult"]] = (0.0, [])
|
_CATALOG_INDEX_MEMORY: tuple[float, List["SeriesResult"]] = (0.0, [])
|
||||||
ProgressCallback = Optional[Callable[[str, Optional[int]], Any]]
|
|
||||||
|
|
||||||
|
|
||||||
def _emit_progress(callback: ProgressCallback, message: str, percent: Optional[int] = None) -> None:
|
|
||||||
if not callable(callback):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
callback(str(message or ""), None if percent is None else int(percent))
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -408,56 +398,37 @@ def _get_soup(url: str, *, session: Optional[RequestsSession] = None) -> Beautif
|
|||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = session or get_requests_session("serienstream", headers=HEADERS)
|
sess = session or get_requests_session("serienstream", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error(f"GET {url} failed: {exc}")
|
_log_error(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
if response.url and response.url != url:
|
||||||
final_url = (response.url or url) if response is not None else url
|
_log_url(response.url, kind="REDIRECT")
|
||||||
body = (response.text or "") if response is not None else ""
|
_log_response_html(url, response.text)
|
||||||
if final_url != url:
|
if _looks_like_cloudflare_challenge(response.text):
|
||||||
_log_url(final_url, kind="REDIRECT")
|
|
||||||
_log_response_html(url, body)
|
|
||||||
if _looks_like_cloudflare_challenge(body):
|
|
||||||
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
||||||
return BeautifulSoup(body, "html.parser")
|
return BeautifulSoup(response.text, "html.parser")
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_html_simple(url: str) -> str:
|
def _get_html_simple(url: str) -> str:
|
||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
_log_visit(url)
|
_log_visit(url)
|
||||||
sess = get_requests_session("serienstream", headers=HEADERS)
|
sess = get_requests_session("serienstream", headers=HEADERS)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
response = sess.get(url, headers=HEADERS, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log_error(f"GET {url} failed: {exc}")
|
_log_error(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
if response.url and response.url != url:
|
||||||
final_url = (response.url or url) if response is not None else url
|
_log_url(response.url, kind="REDIRECT")
|
||||||
body = (response.text or "") if response is not None else ""
|
body = response.text
|
||||||
if final_url != url:
|
|
||||||
_log_url(final_url, kind="REDIRECT")
|
|
||||||
_log_response_html(url, body)
|
_log_response_html(url, body)
|
||||||
if _looks_like_cloudflare_challenge(body):
|
if _looks_like_cloudflare_challenge(body):
|
||||||
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
raise RuntimeError("Cloudflare-Schutz erkannt. requests reicht ggf. nicht aus.")
|
||||||
return body
|
return body
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_soup_simple(url: str) -> BeautifulSoupT:
|
def _get_soup_simple(url: str) -> BeautifulSoupT:
|
||||||
@@ -501,7 +472,6 @@ def _search_series_api(query: str) -> List[SeriesResult]:
|
|||||||
terms.extend([token for token in query.split() if token])
|
terms.extend([token for token in query.split() if token])
|
||||||
seen_urls: set[str] = set()
|
seen_urls: set[str] = set()
|
||||||
for term in terms:
|
for term in terms:
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(
|
response = sess.get(
|
||||||
f"{_get_base_url()}/api/search/suggest",
|
f"{_get_base_url()}/api/search/suggest",
|
||||||
@@ -516,12 +486,6 @@ def _search_series_api(query: str) -> List[SeriesResult]:
|
|||||||
payload = response.json()
|
payload = response.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
shows = payload.get("shows") if isinstance(payload, dict) else None
|
shows = payload.get("shows") if isinstance(payload, dict) else None
|
||||||
if not isinstance(shows, list):
|
if not isinstance(shows, list):
|
||||||
continue
|
continue
|
||||||
@@ -594,7 +558,7 @@ def _search_series_server(query: str) -> List[SeriesResult]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def _extract_catalog_index_from_html(body: str, *, progress_callback: ProgressCallback = None) -> List[SeriesResult]:
|
def _extract_catalog_index_from_html(body: str) -> List[SeriesResult]:
|
||||||
items: List[SeriesResult] = []
|
items: List[SeriesResult] = []
|
||||||
if not body:
|
if not body:
|
||||||
return items
|
return items
|
||||||
@@ -605,9 +569,7 @@ def _extract_catalog_index_from_html(body: str, *, progress_callback: ProgressCa
|
|||||||
)
|
)
|
||||||
anchor_re = re.compile(r"<a[^>]+href=[\"']([^\"']+)[\"'][^>]*>(.*?)</a>", re.IGNORECASE | re.DOTALL)
|
anchor_re = re.compile(r"<a[^>]+href=[\"']([^\"']+)[\"'][^>]*>(.*?)</a>", re.IGNORECASE | re.DOTALL)
|
||||||
data_search_re = re.compile(r"data-search=[\"']([^\"']*)[\"']", re.IGNORECASE)
|
data_search_re = re.compile(r"data-search=[\"']([^\"']*)[\"']", re.IGNORECASE)
|
||||||
for idx, match in enumerate(item_re.finditer(body), start=1):
|
for match in item_re.finditer(body):
|
||||||
if idx == 1 or idx % 200 == 0:
|
|
||||||
_emit_progress(progress_callback, f"Katalog parsen {idx}", 62)
|
|
||||||
block = match.group(0)
|
block = match.group(0)
|
||||||
inner = match.group(1) or ""
|
inner = match.group(1) or ""
|
||||||
anchor_match = anchor_re.search(inner)
|
anchor_match = anchor_re.search(inner)
|
||||||
@@ -689,33 +651,26 @@ def _store_catalog_index_in_cache(items: List[SeriesResult]) -> None:
|
|||||||
_session_cache_set(CATALOG_SEARCH_CACHE_KEY, payload, ttl_seconds=CATALOG_SEARCH_TTL_SECONDS)
|
_session_cache_set(CATALOG_SEARCH_CACHE_KEY, payload, ttl_seconds=CATALOG_SEARCH_TTL_SECONDS)
|
||||||
|
|
||||||
|
|
||||||
def search_series(query: str, *, progress_callback: ProgressCallback = None) -> List[SeriesResult]:
|
def search_series(query: str) -> List[SeriesResult]:
|
||||||
"""Sucht Serien im (/serien)-Katalog nach Titel. Nutzt Cache + Ein-Pass-Filter."""
|
"""Sucht Serien im (/serien)-Katalog nach Titel. Nutzt Cache + Ein-Pass-Filter."""
|
||||||
_ensure_requests()
|
_ensure_requests()
|
||||||
if not _normalize_search_text(query):
|
if not _normalize_search_text(query):
|
||||||
return []
|
return []
|
||||||
_emit_progress(progress_callback, "Server-Suche", 15)
|
|
||||||
server_results = _search_series_server(query)
|
server_results = _search_series_server(query)
|
||||||
if server_results:
|
if server_results:
|
||||||
_emit_progress(progress_callback, f"Server-Treffer: {len(server_results)}", 35)
|
|
||||||
return [entry for entry in server_results if entry.title and _matches_query(query, title=entry.title)]
|
return [entry for entry in server_results if entry.title and _matches_query(query, title=entry.title)]
|
||||||
_emit_progress(progress_callback, "Pruefe Such-Cache", 42)
|
|
||||||
cached = _load_catalog_index_from_cache()
|
cached = _load_catalog_index_from_cache()
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
_emit_progress(progress_callback, f"Cache-Treffer: {len(cached)}", 52)
|
|
||||||
return [entry for entry in cached if entry.title and _matches_query(query, title=entry.title)]
|
return [entry for entry in cached if entry.title and _matches_query(query, title=entry.title)]
|
||||||
|
|
||||||
_emit_progress(progress_callback, "Lade Katalogseite", 58)
|
|
||||||
catalog_url = f"{_get_base_url()}/serien?by=genre"
|
catalog_url = f"{_get_base_url()}/serien?by=genre"
|
||||||
body = _get_html_simple(catalog_url)
|
body = _get_html_simple(catalog_url)
|
||||||
items = _extract_catalog_index_from_html(body, progress_callback=progress_callback)
|
items = _extract_catalog_index_from_html(body)
|
||||||
if not items:
|
if not items:
|
||||||
_emit_progress(progress_callback, "Fallback-Parser", 70)
|
|
||||||
soup = BeautifulSoup(body, "html.parser")
|
soup = BeautifulSoup(body, "html.parser")
|
||||||
items = _catalog_index_from_soup(soup)
|
items = _catalog_index_from_soup(soup)
|
||||||
if items:
|
if items:
|
||||||
_store_catalog_index_in_cache(items)
|
_store_catalog_index_in_cache(items)
|
||||||
_emit_progress(progress_callback, f"Filtere Treffer ({len(items)})", 85)
|
|
||||||
return [entry for entry in items if entry.title and _matches_query(query, title=entry.title)]
|
return [entry for entry in items if entry.title and _matches_query(query, title=entry.title)]
|
||||||
|
|
||||||
|
|
||||||
@@ -1034,8 +989,6 @@ def resolve_redirect(target_url: str) -> Optional[str]:
|
|||||||
_get_soup(_get_base_url(), session=session)
|
_get_soup(_get_base_url(), session=session)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
response = None
|
|
||||||
try:
|
|
||||||
response = session.get(
|
response = session.get(
|
||||||
normalized_url,
|
normalized_url,
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
@@ -1045,12 +998,6 @@ def resolve_redirect(target_url: str) -> Optional[str]:
|
|||||||
if response.url:
|
if response.url:
|
||||||
_log_url(response.url, kind="RESOLVED")
|
_log_url(response.url, kind="RESOLVED")
|
||||||
return response.url if response.url else None
|
return response.url if response.url else None
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def scrape_series_detail(
|
def scrape_series_detail(
|
||||||
@@ -1734,7 +1681,7 @@ class SerienstreamPlugin(BasisPlugin):
|
|||||||
return self._episode_label_cache.get(cache_key, {}).get(episode_label)
|
return self._episode_label_cache.get(cache_key, {}).get(episode_label)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def search_titles(self, query: str, progress_callback: ProgressCallback = None) -> List[str]:
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
query = query.strip()
|
query = query.strip()
|
||||||
if not query:
|
if not query:
|
||||||
self._series_results.clear()
|
self._series_results.clear()
|
||||||
@@ -1748,8 +1695,7 @@ class SerienstreamPlugin(BasisPlugin):
|
|||||||
try:
|
try:
|
||||||
# Nutzt den Katalog (/serien), der jetzt nach Genres gruppiert ist.
|
# Nutzt den Katalog (/serien), der jetzt nach Genres gruppiert ist.
|
||||||
# Alternativ gäbe es ein Ajax-Endpoint, aber der ist nicht immer zuverlässig erreichbar.
|
# Alternativ gäbe es ein Ajax-Endpoint, aber der ist nicht immer zuverlässig erreichbar.
|
||||||
_emit_progress(progress_callback, "Serienstream Suche startet", 10)
|
results = search_series(query)
|
||||||
results = search_series(query, progress_callback=progress_callback)
|
|
||||||
except Exception as exc: # pragma: no cover - defensive logging
|
except Exception as exc: # pragma: no cover - defensive logging
|
||||||
self._series_results.clear()
|
self._series_results.clear()
|
||||||
self._season_cache.clear()
|
self._season_cache.clear()
|
||||||
@@ -1762,7 +1708,6 @@ class SerienstreamPlugin(BasisPlugin):
|
|||||||
self._season_cache.clear()
|
self._season_cache.clear()
|
||||||
self._season_links_cache.clear()
|
self._season_links_cache.clear()
|
||||||
self._episode_label_cache.clear()
|
self._episode_label_cache.clear()
|
||||||
_emit_progress(progress_callback, f"Treffer aufbereitet: {len(results)}", 95)
|
|
||||||
return [result.title for result in results]
|
return [result.title for result in results]
|
||||||
|
|
||||||
def _ensure_seasons(self, title: str) -> List[SeasonInfo]:
|
def _ensure_seasons(self, title: str) -> List[SeasonInfo]:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import hashlib
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||||
from urllib.parse import urlencode, urljoin
|
from urllib.parse import urlencode, urljoin
|
||||||
|
|
||||||
try: # pragma: no cover - optional dependency
|
try: # pragma: no cover - optional dependency
|
||||||
@@ -78,16 +78,6 @@ HEADERS = {
|
|||||||
"Accept-Language": "de-DE,de;q=0.9,en;q=0.8",
|
"Accept-Language": "de-DE,de;q=0.9,en;q=0.8",
|
||||||
"Connection": "keep-alive",
|
"Connection": "keep-alive",
|
||||||
}
|
}
|
||||||
ProgressCallback = Optional[Callable[[str, Optional[int]], Any]]
|
|
||||||
|
|
||||||
|
|
||||||
def _emit_progress(callback: ProgressCallback, message: str, percent: Optional[int] = None) -> None:
|
|
||||||
if not callable(callback):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
callback(str(message or ""), None if percent is None else int(percent))
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
@@ -594,25 +584,15 @@ class TopstreamfilmPlugin(BasisPlugin):
|
|||||||
session = self._get_session()
|
session = self._get_session()
|
||||||
self._log_url(url, kind="VISIT")
|
self._log_url(url, kind="VISIT")
|
||||||
self._notify_url(url)
|
self._notify_url(url)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = session.get(url, timeout=DEFAULT_TIMEOUT)
|
response = session.get(url, timeout=DEFAULT_TIMEOUT)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self._log_error(f"GET {url} failed: {exc}")
|
self._log_error(f"GET {url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
self._log_url(response.url, kind="OK")
|
||||||
final_url = (response.url or url) if response is not None else url
|
self._log_response_html(response.url, response.text)
|
||||||
body = (response.text or "") if response is not None else ""
|
return BeautifulSoup(response.text, "html.parser")
|
||||||
self._log_url(final_url, kind="OK")
|
|
||||||
self._log_response_html(final_url, body)
|
|
||||||
return BeautifulSoup(body, "html.parser")
|
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _get_detail_soup(self, title: str) -> Optional[BeautifulSoupT]:
|
def _get_detail_soup(self, title: str) -> Optional[BeautifulSoupT]:
|
||||||
title = (title or "").strip()
|
title = (title or "").strip()
|
||||||
@@ -834,7 +814,7 @@ class TopstreamfilmPlugin(BasisPlugin):
|
|||||||
# Sonst: Serie via Streams-Accordion parsen (falls vorhanden).
|
# Sonst: Serie via Streams-Accordion parsen (falls vorhanden).
|
||||||
self._parse_stream_accordion(soup, title=title)
|
self._parse_stream_accordion(soup, title=title)
|
||||||
|
|
||||||
async def search_titles(self, query: str, progress_callback: ProgressCallback = None) -> List[str]:
|
async def search_titles(self, query: str) -> List[str]:
|
||||||
"""Sucht Titel ueber eine HTML-Suche.
|
"""Sucht Titel ueber eine HTML-Suche.
|
||||||
|
|
||||||
Erwartetes HTML (Snippet):
|
Erwartetes HTML (Snippet):
|
||||||
@@ -847,7 +827,6 @@ class TopstreamfilmPlugin(BasisPlugin):
|
|||||||
query = (query or "").strip()
|
query = (query or "").strip()
|
||||||
if not query:
|
if not query:
|
||||||
return []
|
return []
|
||||||
_emit_progress(progress_callback, "Topstreamfilm Suche", 15)
|
|
||||||
|
|
||||||
session = self._get_session()
|
session = self._get_session()
|
||||||
url = self._get_base_url() + "/"
|
url = self._get_base_url() + "/"
|
||||||
@@ -855,7 +834,6 @@ class TopstreamfilmPlugin(BasisPlugin):
|
|||||||
request_url = f"{url}?{urlencode(params)}"
|
request_url = f"{url}?{urlencode(params)}"
|
||||||
self._log_url(request_url, kind="GET")
|
self._log_url(request_url, kind="GET")
|
||||||
self._notify_url(request_url)
|
self._notify_url(request_url)
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = session.get(
|
response = session.get(
|
||||||
url,
|
url,
|
||||||
@@ -866,28 +844,15 @@ class TopstreamfilmPlugin(BasisPlugin):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self._log_error(f"GET {request_url} failed: {exc}")
|
self._log_error(f"GET {request_url} failed: {exc}")
|
||||||
raise
|
raise
|
||||||
try:
|
self._log_url(response.url, kind="OK")
|
||||||
final_url = (response.url or request_url) if response is not None else request_url
|
self._log_response_html(response.url, response.text)
|
||||||
body = (response.text or "") if response is not None else ""
|
|
||||||
self._log_url(final_url, kind="OK")
|
|
||||||
self._log_response_html(final_url, body)
|
|
||||||
|
|
||||||
if BeautifulSoup is None:
|
if BeautifulSoup is None:
|
||||||
return []
|
return []
|
||||||
soup = BeautifulSoup(body, "html.parser")
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
hits: List[SearchHit] = []
|
hits: List[SearchHit] = []
|
||||||
items = soup.select("li.TPostMv")
|
for item in soup.select("li.TPostMv"):
|
||||||
total_items = max(1, len(items))
|
|
||||||
for idx, item in enumerate(items, start=1):
|
|
||||||
if idx == 1 or idx % 20 == 0:
|
|
||||||
_emit_progress(progress_callback, f"Treffer pruefen {idx}/{total_items}", 55)
|
|
||||||
anchor = item.select_one("a[href]")
|
anchor = item.select_one("a[href]")
|
||||||
if not anchor:
|
if not anchor:
|
||||||
continue
|
continue
|
||||||
@@ -920,7 +885,6 @@ class TopstreamfilmPlugin(BasisPlugin):
|
|||||||
self._title_to_url[hit.title] = hit.url
|
self._title_to_url[hit.title] = hit.url
|
||||||
titles.append(hit.title)
|
titles.append(hit.title)
|
||||||
self._save_title_url_cache()
|
self._save_title_url_cache()
|
||||||
_emit_progress(progress_callback, f"Fertig: {len(titles)} Treffer", 95)
|
|
||||||
return titles
|
return titles
|
||||||
|
|
||||||
def genres(self) -> List[str]:
|
def genres(self) -> List[str]:
|
||||||
|
|||||||
@@ -71,7 +71,10 @@
|
|||||||
<setting id="tmdb_log_responses" type="bool" label="TMDB API-Antworten loggen" default="false" />
|
<setting id="tmdb_log_responses" type="bool" label="TMDB API-Antworten loggen" default="false" />
|
||||||
</category>
|
</category>
|
||||||
<category label="Update">
|
<category label="Update">
|
||||||
<setting id="update_repo_url" type="text" label="Update-URL (addons.xml)" default="http://127.0.0.1:8080/repo/addons.xml" />
|
<setting id="update_channel" type="enum" label="Update-Kanal" default="0" values="Main|Nightly|Custom" />
|
||||||
|
<setting id="update_repo_url_main" type="text" label="Main URL (addons.xml)" default="https://gitea.it-drui.de/viewit/ViewIT-Kodi-Repo/raw/branch/main/addons.xml" />
|
||||||
|
<setting id="update_repo_url_nightly" type="text" label="Nightly URL (addons.xml)" default="https://gitea.it-drui.de/viewit/ViewIT-Kodi-Repo/raw/branch/nightly/addons.xml" />
|
||||||
|
<setting id="update_repo_url" type="text" label="Custom URL (addons.xml)" default="http://127.0.0.1:8080/repo/addons.xml" />
|
||||||
<setting id="run_update_check" type="action" label="Jetzt nach Updates suchen" action="RunPlugin(plugin://plugin.video.viewit/?action=check_updates)" option="close" />
|
<setting id="run_update_check" type="action" label="Jetzt nach Updates suchen" action="RunPlugin(plugin://plugin.video.viewit/?action=check_updates)" option="close" />
|
||||||
<setting id="update_info" type="text" label="Updates laufen ueber den normalen Kodi-Update-Mechanismus." default="" enable="false" />
|
<setting id="update_info" type="text" label="Updates laufen ueber den normalen Kodi-Update-Mechanismus." default="" enable="false" />
|
||||||
<setting id="update_version_addon" type="text" label="ViewIT Version" default="-" enable="false" />
|
<setting id="update_version_addon" type="text" label="ViewIT Version" default="-" enable="false" />
|
||||||
|
|||||||
155
addon/tmdb.py
155
addon/tmdb.py
@@ -14,7 +14,6 @@ except ImportError: # pragma: no cover
|
|||||||
|
|
||||||
TMDB_API_BASE = "https://api.themoviedb.org/3"
|
TMDB_API_BASE = "https://api.themoviedb.org/3"
|
||||||
TMDB_IMAGE_BASE = "https://image.tmdb.org/t/p"
|
TMDB_IMAGE_BASE = "https://image.tmdb.org/t/p"
|
||||||
MAX_CAST_MEMBERS = 30
|
|
||||||
_TMDB_THREAD_LOCAL = threading.local()
|
_TMDB_THREAD_LOCAL = threading.local()
|
||||||
|
|
||||||
|
|
||||||
@@ -74,17 +73,53 @@ def _fetch_credits(
|
|||||||
return []
|
return []
|
||||||
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
||||||
url = f"{TMDB_API_BASE}/{kind}/{tmdb_id}/credits?{urlencode(params)}"
|
url = f"{TMDB_API_BASE}/{kind}/{tmdb_id}/credits?{urlencode(params)}"
|
||||||
status, payload, body_text = _tmdb_get_json(url=url, timeout=timeout, log=log, log_responses=log_responses)
|
if callable(log):
|
||||||
|
log(f"TMDB GET {url}")
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=timeout)
|
||||||
|
except Exception as exc: # pragma: no cover
|
||||||
|
if callable(log):
|
||||||
|
log(f"TMDB ERROR /{kind}/{{id}}/credits request_failed error={exc!r}")
|
||||||
|
return []
|
||||||
|
status = getattr(response, "status_code", None)
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB RESPONSE /{kind}/{{id}}/credits status={status}")
|
log(f"TMDB RESPONSE /{kind}/{{id}}/credits status={status}")
|
||||||
if log_responses and payload is None and body_text:
|
if status != 200:
|
||||||
log(f"TMDB RESPONSE_BODY /{kind}/{{id}}/credits body={body_text[:2000]}")
|
|
||||||
if status != 200 or not isinstance(payload, dict):
|
|
||||||
return []
|
return []
|
||||||
|
try:
|
||||||
|
payload = response.json() or {}
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
|
if callable(log) and log_responses:
|
||||||
|
try:
|
||||||
|
dumped = json.dumps(payload, ensure_ascii=False)
|
||||||
|
except Exception:
|
||||||
|
dumped = str(payload)
|
||||||
|
log(f"TMDB RESPONSE_BODY /{kind}/{{id}}/credits body={dumped[:2000]}")
|
||||||
|
|
||||||
cast_payload = payload.get("cast") or []
|
cast_payload = payload.get("cast") or []
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB CREDITS /{kind}/{{id}}/credits cast={len(cast_payload)}")
|
log(f"TMDB CREDITS /{kind}/{{id}}/credits cast={len(cast_payload)}")
|
||||||
return _parse_cast_payload(cast_payload)
|
with_images: List[TmdbCastMember] = []
|
||||||
|
without_images: List[TmdbCastMember] = []
|
||||||
|
for entry in cast_payload:
|
||||||
|
name = (entry.get("name") or "").strip()
|
||||||
|
role = (entry.get("character") or "").strip()
|
||||||
|
thumb = _image_url(entry.get("profile_path") or "", size="w185")
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
member = TmdbCastMember(name=name, role=role, thumb=thumb)
|
||||||
|
if thumb:
|
||||||
|
with_images.append(member)
|
||||||
|
else:
|
||||||
|
without_images.append(member)
|
||||||
|
|
||||||
|
# Viele Kodi-Skins zeigen bei fehlendem Thumbnail Platzhalter-Köpfe.
|
||||||
|
# Bevorzugt daher Cast-Einträge mit Bild; nur wenn gar keine Bilder existieren,
|
||||||
|
# geben wir Namen ohne Bild zurück.
|
||||||
|
if with_images:
|
||||||
|
return with_images[:30]
|
||||||
|
return without_images[:30]
|
||||||
|
|
||||||
|
|
||||||
def _parse_cast_payload(cast_payload: object) -> List[TmdbCastMember]:
|
def _parse_cast_payload(cast_payload: object) -> List[TmdbCastMember]:
|
||||||
@@ -106,8 +141,8 @@ def _parse_cast_payload(cast_payload: object) -> List[TmdbCastMember]:
|
|||||||
else:
|
else:
|
||||||
without_images.append(member)
|
without_images.append(member)
|
||||||
if with_images:
|
if with_images:
|
||||||
return with_images[:MAX_CAST_MEMBERS]
|
return with_images[:30]
|
||||||
return without_images[:MAX_CAST_MEMBERS]
|
return without_images[:30]
|
||||||
|
|
||||||
|
|
||||||
def _tmdb_get_json(
|
def _tmdb_get_json(
|
||||||
@@ -128,9 +163,13 @@ def _tmdb_get_json(
|
|||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB GET {url}")
|
log(f"TMDB GET {url}")
|
||||||
sess = session or _get_tmdb_session() or requests.Session()
|
sess = session or _get_tmdb_session() or requests.Session()
|
||||||
response = None
|
|
||||||
try:
|
try:
|
||||||
response = sess.get(url, timeout=timeout)
|
response = sess.get(url, timeout=timeout)
|
||||||
|
except Exception as exc: # pragma: no cover
|
||||||
|
if callable(log):
|
||||||
|
log(f"TMDB ERROR request_failed url={url} error={exc!r}")
|
||||||
|
return None, None, ""
|
||||||
|
|
||||||
status = getattr(response, "status_code", None)
|
status = getattr(response, "status_code", None)
|
||||||
payload: object | None = None
|
payload: object | None = None
|
||||||
body_text = ""
|
body_text = ""
|
||||||
@@ -141,16 +180,6 @@ def _tmdb_get_json(
|
|||||||
body_text = (response.text or "").strip()
|
body_text = (response.text or "").strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
body_text = ""
|
body_text = ""
|
||||||
except Exception as exc: # pragma: no cover
|
|
||||||
if callable(log):
|
|
||||||
log(f"TMDB ERROR request_failed url={url} error={exc!r}")
|
|
||||||
return None, None, ""
|
|
||||||
finally:
|
|
||||||
if response is not None:
|
|
||||||
try:
|
|
||||||
response.close()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB RESPONSE status={status} url={url}")
|
log(f"TMDB RESPONSE status={status} url={url}")
|
||||||
@@ -185,17 +214,49 @@ def fetch_tv_episode_credits(
|
|||||||
return []
|
return []
|
||||||
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
||||||
url = f"{TMDB_API_BASE}/tv/{tmdb_id}/season/{season_number}/episode/{episode_number}/credits?{urlencode(params)}"
|
url = f"{TMDB_API_BASE}/tv/{tmdb_id}/season/{season_number}/episode/{episode_number}/credits?{urlencode(params)}"
|
||||||
status, payload, body_text = _tmdb_get_json(url=url, timeout=timeout, log=log, log_responses=log_responses)
|
if callable(log):
|
||||||
|
log(f"TMDB GET {url}")
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=timeout)
|
||||||
|
except Exception as exc: # pragma: no cover
|
||||||
|
if callable(log):
|
||||||
|
log(f"TMDB ERROR /tv/{{id}}/season/{{n}}/episode/{{e}}/credits request_failed error={exc!r}")
|
||||||
|
return []
|
||||||
|
status = getattr(response, "status_code", None)
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB RESPONSE /tv/{{id}}/season/{{n}}/episode/{{e}}/credits status={status}")
|
log(f"TMDB RESPONSE /tv/{{id}}/season/{{n}}/episode/{{e}}/credits status={status}")
|
||||||
if log_responses and payload is None and body_text:
|
if status != 200:
|
||||||
log(f"TMDB RESPONSE_BODY /tv/{{id}}/season/{{n}}/episode/{{e}}/credits body={body_text[:2000]}")
|
|
||||||
if status != 200 or not isinstance(payload, dict):
|
|
||||||
return []
|
return []
|
||||||
|
try:
|
||||||
|
payload = response.json() or {}
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
|
if callable(log) and log_responses:
|
||||||
|
try:
|
||||||
|
dumped = json.dumps(payload, ensure_ascii=False)
|
||||||
|
except Exception:
|
||||||
|
dumped = str(payload)
|
||||||
|
log(f"TMDB RESPONSE_BODY /tv/{{id}}/season/{{n}}/episode/{{e}}/credits body={dumped[:2000]}")
|
||||||
|
|
||||||
cast_payload = payload.get("cast") or []
|
cast_payload = payload.get("cast") or []
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB CREDITS /tv/{{id}}/season/{{n}}/episode/{{e}}/credits cast={len(cast_payload)}")
|
log(f"TMDB CREDITS /tv/{{id}}/season/{{n}}/episode/{{e}}/credits cast={len(cast_payload)}")
|
||||||
return _parse_cast_payload(cast_payload)
|
with_images: List[TmdbCastMember] = []
|
||||||
|
without_images: List[TmdbCastMember] = []
|
||||||
|
for entry in cast_payload:
|
||||||
|
name = (entry.get("name") or "").strip()
|
||||||
|
role = (entry.get("character") or "").strip()
|
||||||
|
thumb = _image_url(entry.get("profile_path") or "", size="w185")
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
member = TmdbCastMember(name=name, role=role, thumb=thumb)
|
||||||
|
if thumb:
|
||||||
|
with_images.append(member)
|
||||||
|
else:
|
||||||
|
without_images.append(member)
|
||||||
|
if with_images:
|
||||||
|
return with_images[:30]
|
||||||
|
return without_images[:30]
|
||||||
|
|
||||||
|
|
||||||
def lookup_tv_show(
|
def lookup_tv_show(
|
||||||
@@ -485,13 +546,27 @@ def lookup_tv_season_summary(
|
|||||||
|
|
||||||
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
||||||
url = f"{TMDB_API_BASE}/tv/{tmdb_id}/season/{season_number}?{urlencode(params)}"
|
url = f"{TMDB_API_BASE}/tv/{tmdb_id}/season/{season_number}?{urlencode(params)}"
|
||||||
status, payload, body_text = _tmdb_get_json(url=url, timeout=timeout, log=log, log_responses=log_responses)
|
if callable(log):
|
||||||
|
log(f"TMDB GET {url}")
|
||||||
|
try:
|
||||||
|
response = requests.get(url, timeout=timeout)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
status = getattr(response, "status_code", None)
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB RESPONSE /tv/{{id}}/season/{{n}} status={status}")
|
log(f"TMDB RESPONSE /tv/{{id}}/season/{{n}} status={status}")
|
||||||
if log_responses and payload is None and body_text:
|
if status != 200:
|
||||||
log(f"TMDB RESPONSE_BODY /tv/{{id}}/season/{{n}} body={body_text[:2000]}")
|
|
||||||
if status != 200 or not isinstance(payload, dict):
|
|
||||||
return None
|
return None
|
||||||
|
try:
|
||||||
|
payload = response.json() or {}
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
if callable(log) and log_responses:
|
||||||
|
try:
|
||||||
|
dumped = json.dumps(payload, ensure_ascii=False)
|
||||||
|
except Exception:
|
||||||
|
dumped = str(payload)
|
||||||
|
log(f"TMDB RESPONSE_BODY /tv/{{id}}/season/{{n}} body={dumped[:2000]}")
|
||||||
|
|
||||||
plot = (payload.get("overview") or "").strip()
|
plot = (payload.get("overview") or "").strip()
|
||||||
poster_path = (payload.get("poster_path") or "").strip()
|
poster_path = (payload.get("poster_path") or "").strip()
|
||||||
@@ -519,9 +594,27 @@ def lookup_tv_season(
|
|||||||
return None
|
return None
|
||||||
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
params = {"api_key": api_key, "language": (language or "de-DE").strip()}
|
||||||
url = f"{TMDB_API_BASE}/tv/{tmdb_id}/season/{season_number}?{urlencode(params)}"
|
url = f"{TMDB_API_BASE}/tv/{tmdb_id}/season/{season_number}?{urlencode(params)}"
|
||||||
status, payload, body_text = _tmdb_get_json(url=url, timeout=timeout, log=log, log_responses=log_responses)
|
if callable(log):
|
||||||
episodes = (payload or {}).get("episodes") if isinstance(payload, dict) else []
|
log(f"TMDB GET {url}")
|
||||||
episodes = episodes or []
|
try:
|
||||||
|
response = requests.get(url, timeout=timeout)
|
||||||
|
except Exception as exc: # pragma: no cover
|
||||||
|
if callable(log):
|
||||||
|
log(f"TMDB ERROR /tv/{{id}}/season/{{n}} request_failed error={exc!r}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
status = getattr(response, "status_code", None)
|
||||||
|
payload = None
|
||||||
|
body_text = ""
|
||||||
|
try:
|
||||||
|
payload = response.json() or {}
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
body_text = (response.text or "").strip()
|
||||||
|
except Exception:
|
||||||
|
body_text = ""
|
||||||
|
|
||||||
|
episodes = (payload or {}).get("episodes") or []
|
||||||
if callable(log):
|
if callable(log):
|
||||||
log(f"TMDB RESPONSE /tv/{{id}}/season/{{n}} status={status} episodes={len(episodes)}")
|
log(f"TMDB RESPONSE /tv/{{id}}/season/{{n}} status={status} episodes={len(episodes)}")
|
||||||
if log_responses:
|
if log_responses:
|
||||||
|
|||||||
Reference in New Issue
Block a user