130 lines
5.7 KiB
Python
130 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Why isn't auto-relay starting for nomadvlog despite ops-neko ready."""
|
|
import json
|
|
import sys
|
|
import paramiko
|
|
import httpx
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
CREDS = [("hackrobot", "Xiao4669805@"), ("hackrobot", "Xiao4669805@!"), ("admin", "Xiao4669805@")]
|
|
|
|
|
|
def login(base: str) -> httpx.Client:
|
|
for u, p in CREDS:
|
|
c = httpx.Client(base_url=base, timeout=40, follow_redirects=True)
|
|
r = c.post("/api/auth/login", json={"username": u, "password": p})
|
|
if r.status_code < 400:
|
|
print(f"login {base} as {u} ok")
|
|
return c
|
|
c.close()
|
|
raise SystemExit(f"login fail {base}")
|
|
|
|
|
|
def main() -> None:
|
|
for base in ("https://dy.nomadro.com", "https://dy.nomadro.cn", "https://dylive.nomadro.com"):
|
|
try:
|
|
h = httpx.get(f"{base}/api/health", timeout=15)
|
|
print(base, "health", h.status_code, h.text[:80])
|
|
except Exception as e:
|
|
print(base, "health ERR", e)
|
|
|
|
# prefer physical (assign lives there for dual deploy)
|
|
bases = ["https://dy.nomadro.com", "https://dy.nomadro.cn"]
|
|
c = None
|
|
used = None
|
|
for b in bases:
|
|
try:
|
|
c = login(b)
|
|
used = b
|
|
break
|
|
except Exception as e:
|
|
print("login skip", b, e)
|
|
if not c:
|
|
raise SystemExit("no login")
|
|
|
|
print("\n=== using", used, "===")
|
|
for path in (
|
|
"/api/youtube/relay/status",
|
|
"/api/youtube/assign/groups",
|
|
"/api/youtube/relay/settings",
|
|
"/api/ops/neko/remote-catalog",
|
|
):
|
|
try:
|
|
r = c.get(path)
|
|
print(f"\n--- GET {path} {r.status_code} ---")
|
|
data = r.json() if r.headers.get("content-type", "").startswith("application/json") else {"raw": r.text[:500]}
|
|
if path.endswith("groups"):
|
|
groups = data.get("groups") or data if isinstance(data, list) else data.get("groups") or []
|
|
if isinstance(data, dict) and "groups" not in data and isinstance(data.get("items"), list):
|
|
groups = data["items"]
|
|
if not isinstance(groups, list):
|
|
# maybe top-level list
|
|
groups = data if isinstance(data, list) else []
|
|
print("groups", len(groups) if isinstance(groups, list) else type(groups))
|
|
for g in (groups if isinstance(groups, list) else [])[:20]:
|
|
if not isinstance(g, dict):
|
|
continue
|
|
name = g.get("youtube_title") or g.get("name") or g.get("id")
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"id": g.get("id"),
|
|
"title": name,
|
|
"category": g.get("category"),
|
|
"enabled": g.get("enabled"),
|
|
"neko_open_prefer": g.get("neko_open_prefer"),
|
|
"ops_slot": g.get("ops_neko_slot"),
|
|
"ops_url": (g.get("ops_neko_open_url") or "")[:60],
|
|
"neko_id": g.get("neko_instance_id"),
|
|
"neko_en": g.get("neko_enabled"),
|
|
"stream_key_set": bool(str(g.get("stream_key") or "").strip()),
|
|
},
|
|
ensure_ascii=False,
|
|
)
|
|
)
|
|
elif path.endswith("settings"):
|
|
print(json.dumps(data, ensure_ascii=False, indent=2)[:2000])
|
|
elif path.endswith("status"):
|
|
# summarize
|
|
if isinstance(data, dict):
|
|
print("keys", sorted(data.keys())[:40])
|
|
for k in ("auto_enabled", "auto_relay", "master", "exclusive", "settings", "global"):
|
|
if k in data:
|
|
print(k, data[k])
|
|
sessions = data.get("sessions") or data.get("groups") or data.get("items") or []
|
|
if isinstance(sessions, list):
|
|
print("session_count", len(sessions))
|
|
for s in sessions[:15]:
|
|
if isinstance(s, dict):
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"id": s.get("group_id") or s.get("id"),
|
|
"title": s.get("title") or s.get("youtube_title"),
|
|
"state": s.get("state") or s.get("status"),
|
|
"running": s.get("running"),
|
|
"reason": s.get("reason") or s.get("wait_reason") or s.get("message"),
|
|
"dy_live": s.get("dy_live") or s.get("source_live"),
|
|
"ffmpeg": s.get("ffmpeg_pid") or s.get("pid"),
|
|
},
|
|
ensure_ascii=False,
|
|
)
|
|
)
|
|
print(json.dumps({k: data[k] for k in data if k in (
|
|
"auto_push", "auto_enabled", "relay_auto", "worker", "exclusive_live",
|
|
"time_slot", "settings", "flags", "pipeline"
|
|
)}, ensure_ascii=False, indent=2)[:1500])
|
|
else:
|
|
print(json.dumps(data, ensure_ascii=False)[:1500])
|
|
except Exception as e:
|
|
print(path, "ERR", e)
|
|
|
|
# also dump kv / relay flags from physical via ssh if needed
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|