Trackers: ajoute tr4ker (SPA React, auth cookie) + jetons Crédit
Type tr4ker : login cookie TR4KER_session via POST /api/auth/login {identifier,
password}, profil GET /api/me. Ratio = (uploaded+bonus_upload)/(downloaded+
bonus_download), garde-fou download=0 -> 1 Go. Jetons = champ money, libellé
token_currency_name (Crédit).
This commit is contained in:
@@ -165,7 +165,47 @@ async def _fetch_torr9(spec: TrackerSpec) -> TrackerStat:
|
||||
)
|
||||
|
||||
|
||||
_FETCHERS = {"unit3d_nuxt": _fetch_unit3d, "torr9": _fetch_torr9}
|
||||
async def _fetch_tr4ker(spec: TrackerSpec) -> TrackerStat:
|
||||
"""tr4ker : SPA React, API même origine. Login cookie (JWT `TR4KER_session`) via
|
||||
`POST /api/auth/login` body `{identifier,password}` -> `{ok:true}`, puis `GET /api/me`.
|
||||
Ratio comme le site : (uploaded + bonus_upload) / (downloaded + bonus_download) ;
|
||||
si rien n'a été téléchargé, on compte 1 Go (le site fait pareil via bonus_download,
|
||||
ça évite un ratio infini). Système de jetons = champ `money` (libellé `token_currency_name`)."""
|
||||
if not (spec.base_url and spec.username and spec.password):
|
||||
return TrackerStat(spec.key, spec.label, ok=False, error="non configuré")
|
||||
|
||||
async with httpx.AsyncClient(
|
||||
timeout=20, follow_redirects=True, headers={"User-Agent": _UA},
|
||||
) as client:
|
||||
r = await client.post(
|
||||
f"{spec.base_url}/api/auth/login",
|
||||
json={"identifier": spec.username, "password": spec.password},
|
||||
)
|
||||
try:
|
||||
d = r.json()
|
||||
except ValueError:
|
||||
raise _AuthError(f"login HTTP {r.status_code}")
|
||||
if not d.get("ok"):
|
||||
raise _AuthError(str(d.get("error") or d.get("message") or "login refusé"))
|
||||
me = await client.get(f"{spec.base_url}/api/me") # cookie de session porté par le client
|
||||
if me.status_code != 200:
|
||||
raise _AuthError(f"me HTTP {me.status_code}")
|
||||
u = me.json()
|
||||
|
||||
up = int(u.get("uploaded", 0) or 0) + int(u.get("bonus_upload", 0) or 0)
|
||||
down = int(u.get("downloaded", 0) or 0) + int(u.get("bonus_download", 0) or 0)
|
||||
if down <= 0:
|
||||
down = 10 ** 9 # rien téléchargé -> on compte 1 Go (pas de ratio infini)
|
||||
money = u.get("money")
|
||||
return TrackerStat(
|
||||
spec.key, spec.label, ok=True,
|
||||
ratio=up / down, up_bytes=up, down_bytes=down,
|
||||
tokens=int(money) if money is not None else None,
|
||||
tokens_label=str(u.get("token_currency_name") or "crédits"),
|
||||
)
|
||||
|
||||
|
||||
_FETCHERS = {"unit3d_nuxt": _fetch_unit3d, "torr9": _fetch_torr9, "tr4ker": _fetch_tr4ker}
|
||||
|
||||
|
||||
async def _fetch_one(spec: TrackerSpec) -> TrackerStat:
|
||||
|
||||
Reference in New Issue
Block a user