:chore: Initialisation du projet
This commit is contained in:
1 parent
75a8c6addd
commit
6278d19618
27 files changed
+4418
-81
No files matched your search
@@ -0,0 +1,40 @@
|
||||
from pathlib import PurePath
|
||||
|
||||
import httpx
|
||||
|
||||
|
||||
class RadarrClient:
|
||||
def __init__(self, url: str, api_key: str) -> None:
|
||||
self._url = url.rstrip("/")
|
||||
self._headers = {"X-Api-Key": api_key}
|
||||
|
||||
async def _get(self, endpoint: str) -> object:
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
response = await client.get(f"{self._url}/api/v3/{endpoint}", headers=self._headers)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def system_status(self) -> dict:
|
||||
result = await self._get("system/status")
|
||||
if not isinstance(result, dict):
|
||||
raise ValueError("Réponse Radarr inattendue")
|
||||
return result
|
||||
|
||||
async def movies(self) -> list[dict]:
|
||||
result = await self._get("movie")
|
||||
if not isinstance(result, list):
|
||||
raise ValueError("Réponse Radarr inattendue")
|
||||
return result
|
||||
|
||||
|
||||
def movie_file_path(movie: dict) -> str | None:
|
||||
movie_file = movie.get("movieFile") or {}
|
||||
path = movie_file.get("path")
|
||||
if path:
|
||||
return str(path)
|
||||
relative_path = movie_file.get("relativePath")
|
||||
movie_path = movie.get("path")
|
||||
if relative_path and movie_path:
|
||||
return str(PurePath(str(movie_path)) / str(relative_path))
|
||||
return None
|
||||
|
||||
Reference in new issue
Block a user