- Added comprehensive documentation for the ViewIt Plugin System, detailing the plugin loading process, required methods, optional features, and community extension workflow. - Updated project notes to reflect the current structure, build process, search logic, and known issues. - Introduced new build scripts for installing the add-on and creating ZIP packages. - Added test scripts for TMDB API integration, including argument parsing and logging functionality. - Enhanced existing plugins with improved search logic and error handling.
35 lines
985 B
Python
35 lines
985 B
Python
#!/usr/bin/env python3
|
|
"""Shared requests.Session pooling for plugins.
|
|
|
|
Goal: reuse TCP connections/cookies across multiple HTTP calls within a Kodi session.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
try: # pragma: no cover - optional dependency
|
|
import requests
|
|
except Exception: # pragma: no cover
|
|
requests = None
|
|
|
|
_SESSIONS: Dict[str, Any] = {}
|
|
|
|
|
|
def get_requests_session(key: str, *, headers: Optional[dict[str, str]] = None):
|
|
"""Return a cached `requests.Session()` for the given key."""
|
|
if requests is None:
|
|
raise RuntimeError("requests ist nicht verfuegbar.")
|
|
key = (key or "").strip() or "default"
|
|
session = _SESSIONS.get(key)
|
|
if session is None:
|
|
session = requests.Session()
|
|
_SESSIONS[key] = session
|
|
if headers:
|
|
try:
|
|
session.headers.update({str(k): str(v) for k, v in headers.items() if k and v})
|
|
except Exception:
|
|
pass
|
|
return session
|
|
|