93 lines
3.7 KiB
Python
93 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only: sample cover URLs after login on dy.nomadro.com. No config changes."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import httpx
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
|
|
|
|
BASE = "https://dy.nomadro.com"
|
|
# known from earlier unit files in conversation history for this deploy
|
|
USER = "hackrobot"
|
|
PASS = "Xiao4669805@"
|
|
|
|
with httpx.Client(follow_redirects=False, timeout=25) as cl:
|
|
r = cl.post(f"{BASE}/api/auth/login", json={"username": USER, "password": PASS})
|
|
print("login", r.status_code, r.text[:120], flush=True)
|
|
token = ""
|
|
try:
|
|
token = (r.json() or {}).get("token") or (r.json() or {}).get("access_token") or ""
|
|
except Exception:
|
|
pass
|
|
# cookie jar may also work
|
|
headers = {"Authorization": f"Bearer {token}"} if token else {}
|
|
for path in ["/api/sessions?status=live", "/api/sessions?live=1", "/api/sessions"]:
|
|
rr = cl.get(f"{BASE}{path}", headers=headers)
|
|
print(f"\n{path} -> {rr.status_code}", flush=True)
|
|
if rr.status_code != 200:
|
|
print(rr.text[:200], flush=True)
|
|
continue
|
|
data = rr.json()
|
|
sessions = data.get("sessions") or data.get("items") or data if isinstance(data, list) else []
|
|
if isinstance(data, dict) and not sessions:
|
|
# try nested
|
|
for k, v in data.items():
|
|
if isinstance(v, list) and v:
|
|
sessions = v
|
|
print("using key", k, flush=True)
|
|
break
|
|
print("count", len(sessions) if isinstance(sessions, list) else type(sessions), flush=True)
|
|
n = 0
|
|
for s in (sessions if isinstance(sessions, list) else [])[:8]:
|
|
if not isinstance(s, dict):
|
|
continue
|
|
if s.get("ended_at") and not s.get("live"):
|
|
# still show a few with covers
|
|
pass
|
|
urls = {
|
|
"avatar_url": s.get("avatar_url"),
|
|
"cover_url": s.get("cover_url"),
|
|
"cover_proxy_url": s.get("cover_proxy_url"),
|
|
"id": s.get("id"),
|
|
"anchor": s.get("anchor_name") or s.get("room_id"),
|
|
"ended": s.get("ended_at"),
|
|
}
|
|
print(urls, flush=True)
|
|
for label in ("avatar_url", "cover_url", "cover_proxy_url"):
|
|
u = urls.get(label)
|
|
if not u or not str(u).startswith("http"):
|
|
continue
|
|
try:
|
|
ir = cl.get(str(u), headers=headers if "dy.nomadro.com" in str(u) else None)
|
|
print(f" GET {label} -> {ir.status_code} ctype={ir.headers.get('content-type','')[:40]} len={len(ir.content)}", flush=True)
|
|
except Exception as ex:
|
|
print(f" GET {label} ERR {ex}", flush=True)
|
|
# also try api cover
|
|
sid = s.get("id")
|
|
if sid:
|
|
try:
|
|
ir = cl.get(f"{BASE}/api/sessions/{sid}/cover", headers=headers)
|
|
print(f" GET /api/sessions/{sid}/cover -> {ir.status_code} ctype={ir.headers.get('content-type','')[:40]}", flush=True)
|
|
except Exception as ex:
|
|
print(f" cover api ERR {ex}", flush=True)
|
|
n += 1
|
|
if n >= 5:
|
|
break
|
|
if rr.status_code == 200:
|
|
break
|
|
|
|
# public s3 host
|
|
for u in [
|
|
"https://s3.nomadro.com/",
|
|
"https://dy.nomadro.com/covers/",
|
|
]:
|
|
try:
|
|
r = cl.get(u)
|
|
print(f"{u} -> {r.status_code}", flush=True)
|
|
except Exception as ex:
|
|
print(f"{u} ERR {ex}", flush=True)
|
|
|
|
print("DONE", flush=True)
|