dev: TMDB API-Key automatisch aus Kodi-Scraper ermitteln
This commit is contained in:
@@ -52,6 +52,24 @@ def _require_init() -> None:
|
||||
print("[ViewIT/metadata] WARNUNG: metadata.init() wurde nicht aufgerufen – Metadaten-Funktionen arbeiten mit Standardwerten!", file=sys.stderr)
|
||||
|
||||
|
||||
def _resolve_tmdb_api_key(user_key: str) -> str:
|
||||
"""Key aus ViewIT-Settings, installiertem Kodi-Scraper oder Community-Fallback."""
|
||||
if user_key:
|
||||
return user_key
|
||||
if xbmcaddon:
|
||||
for addon_id in (
|
||||
"metadata.tvshows.themoviedb.org.python",
|
||||
"metadata.themoviedb.org.python",
|
||||
):
|
||||
try:
|
||||
key = xbmcaddon.Addon(addon_id).getSetting("tmdb_apikey")
|
||||
if key:
|
||||
return key
|
||||
except RuntimeError:
|
||||
pass
|
||||
return "80246691939720672db3fc71c74e0ef2"
|
||||
|
||||
|
||||
def init(
|
||||
*,
|
||||
get_setting_string: Callable[[str], str],
|
||||
@@ -153,7 +171,7 @@ def tmdb_labels_and_art(title: str) -> tuple[dict[str, str], dict[str, str], lis
|
||||
art: dict[str, str] = {}
|
||||
cast: list[TmdbCastMember] = []
|
||||
query = (title or "").strip()
|
||||
api_key = _get_setting_string("tmdb_api_key").strip()
|
||||
api_key = _resolve_tmdb_api_key(_get_setting_string("tmdb_api_key").strip())
|
||||
log_requests = _get_setting_bool("tmdb_log_requests", default=False)
|
||||
log_responses = _get_setting_bool("tmdb_log_responses", default=False)
|
||||
if api_key:
|
||||
@@ -295,7 +313,7 @@ def tmdb_episode_labels_and_art(*, title: str, season_label: str, episode_label:
|
||||
season_key = (tmdb_id, season_number, language, flags)
|
||||
cached_season = tmdb_cache_get(_TMDB_SEASON_CACHE, season_key)
|
||||
if cached_season is None:
|
||||
api_key = _get_setting_string("tmdb_api_key").strip()
|
||||
api_key = _resolve_tmdb_api_key(_get_setting_string("tmdb_api_key").strip())
|
||||
if not api_key:
|
||||
return {"title": episode_label}, {}
|
||||
log_requests = _get_setting_bool("tmdb_log_requests", default=False)
|
||||
@@ -358,7 +376,7 @@ def tmdb_episode_cast(*, title: str, season_label: str, episode_label: str) -> l
|
||||
if cached is not None:
|
||||
return list(cached)
|
||||
|
||||
api_key = _get_setting_string("tmdb_api_key").strip()
|
||||
api_key = _resolve_tmdb_api_key(_get_setting_string("tmdb_api_key").strip())
|
||||
if not api_key:
|
||||
tmdb_cache_set(_TMDB_EPISODE_CAST_CACHE, cache_key, [])
|
||||
return []
|
||||
@@ -398,7 +416,7 @@ def tmdb_season_labels_and_art(
|
||||
show_plot = _get_setting_bool("tmdb_show_plot", default=True)
|
||||
show_art = _get_setting_bool("tmdb_show_art", default=True)
|
||||
flags = f"p{int(show_plot)}a{int(show_art)}"
|
||||
api_key = _get_setting_string("tmdb_api_key").strip()
|
||||
api_key = _resolve_tmdb_api_key(_get_setting_string("tmdb_api_key").strip())
|
||||
log_requests = _get_setting_bool("tmdb_log_requests", default=False)
|
||||
log_responses = _get_setting_bool("tmdb_log_responses", default=False)
|
||||
log_fn = tmdb_file_log if (log_requests or log_responses) else None
|
||||
|
||||
Reference in New Issue
Block a user