Files
rename-mvp/app/services/tvdb_client.py
T
2026-03-07 09:59:27 +01:00

24 lines
902 B
Python

import httpx
from app.config import TVDB_BASE_URL, TVDB_REQUEST_TIMEOUT_SECONDS
from app.services.tvdb_auth_service import TvdbAuthService
class TvdbClient:
def __init__(self):
self.auth = TvdbAuthService()
def get(self, path: str, params: dict | None = None) -> dict:
token = self.auth.get_valid_token()
headers = {"Authorization": f"Bearer {token}"}
with httpx.Client(timeout=TVDB_REQUEST_TIMEOUT_SECONDS) as client:
response = client.get(f"{TVDB_BASE_URL}{path}", params=params, headers=headers)
if response.status_code == 401:
token = self.auth.login_and_store_token()["token"]
headers = {"Authorization": f"Bearer {token}"}
response = client.get(f"{TVDB_BASE_URL}{path}", params=params, headers=headers)
response.raise_for_status()
return response.json()