Files
ViewIT/dist/plugin.video.viewit/http_session_pool.py
itdrui.de ee275bee47 Implement ViewIt Plugin System Documentation and Update Project Notes
- 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.
2026-02-01 17:55:30 +01:00

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