✨ qBittorrent: identifiants optionnels via bypass d'authentification (pas d'API key native)
This commit is contained in:
1 parent
95e5ead67a
commit
e8bbbc7d1e
5 files changed
+57
-18
No files matched your search
+16
-9
@@ -6,21 +6,28 @@ import httpx
|
||||
|
||||
|
||||
class QbittorrentClient:
|
||||
def __init__(self, url: str, username: str, password: str) -> None:
|
||||
"""Client WebUI (API v2). Identifiants optionnels: sans eux, aucun login
|
||||
n'est effectue — qBittorrent doit alors autoriser la plage IP (bypass
|
||||
d'authentification), car il n'existe pas d'API key cote qBittorrent."""
|
||||
|
||||
def __init__(
|
||||
self, url: str, username: str | None = None, password: str | None = None
|
||||
) -> None:
|
||||
self._url = url.rstrip("/")
|
||||
self._username = username
|
||||
self._password = password
|
||||
|
||||
async def _request(self, method: str, endpoint: str, **kwargs) -> httpx.Response:
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
login = await client.post(
|
||||
f"{self._url}/api/v2/auth/login",
|
||||
data={"username": self._username, "password": self._password},
|
||||
headers={"Referer": self._url},
|
||||
)
|
||||
login.raise_for_status()
|
||||
if login.text.strip() != "Ok.":
|
||||
raise ValueError("Authentification qBittorrent refusée")
|
||||
if self._username and self._password:
|
||||
login = await client.post(
|
||||
f"{self._url}/api/v2/auth/login",
|
||||
data={"username": self._username, "password": self._password},
|
||||
headers={"Referer": self._url},
|
||||
)
|
||||
login.raise_for_status()
|
||||
if login.text.strip() != "Ok.":
|
||||
raise ValueError("Authentification qBittorrent refusée")
|
||||
response = await client.request(
|
||||
method,
|
||||
f"{self._url}{endpoint}",
|
||||
|
||||
Reference in new issue
Block a user