121 lines
4.0 KiB
Python
121 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Probe YouTube live-map: who is counted as 在播 and why."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def ssh():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, t=120):
|
|
print(f"\n$ {cmd[:220]}", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
code = o.channel.recv_exit_status()
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-20000:] if len(out) > 20000 else out, flush=True)
|
|
return code, out
|
|
|
|
|
|
c = ssh()
|
|
code, _ = run(
|
|
c,
|
|
r"""
|
|
set -euo pipefail
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
import asyncio, json, time
|
|
from app import youtube_live
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline as pipe
|
|
from app import youtube_neko as yn
|
|
|
|
m = asyncio.run(youtube_live.build_live_map(force=True))
|
|
print("live_count", m.get("live_count"), "checked_at_age", round(time.time()-float(m.get("checked_at") or 0),1),
|
|
"svc_error", m.get("svc_error"), "refreshing", m.get("refreshing"))
|
|
|
|
live_rows=[]
|
|
for k,v in (m.get("entries") or {}).items():
|
|
if not v.get("is_live"):
|
|
continue
|
|
st = v.get("studio") if isinstance(v.get("studio"), dict) else {}
|
|
live_rows.append({
|
|
"key": k,
|
|
"title": v.get("title") or v.get("name") or v.get("label") or "",
|
|
"source": v.get("source"),
|
|
"assign_group_id": (str(v.get("assign_group_id") or "")[:8] or None),
|
|
"channel_id": (str(v.get("channel_id") or v.get("youtube_channel_id") or "")[:28] or None),
|
|
"studio": {
|
|
"on_air": st.get("on_air"),
|
|
"encoder_receiving": st.get("encoder_receiving"),
|
|
"encoder_lost": st.get("encoder_lost"),
|
|
"live_status": st.get("live_status"),
|
|
"health": st.get("health"),
|
|
"preparing_stream": st.get("preparing_stream"),
|
|
"age_sec": st.get("age_sec"),
|
|
"detect_source": st.get("detect_source"),
|
|
} if st else None,
|
|
"is_pushing_hint": v.get("is_pushing"),
|
|
})
|
|
|
|
print("LIVE_ENTRIES", len(live_rows))
|
|
print(json.dumps(live_rows, ensure_ascii=False, indent=2))
|
|
|
|
st = pipe.status()
|
|
push=[]
|
|
for r in (st.get("groups") or []):
|
|
if r.get("is_pushing") or str(r.get("business_status") or "") in {"streaming","relay_slow","relay_starting"}:
|
|
snap=((r.get("neko") or {}).get("studio") or {})
|
|
push.append({
|
|
"name": r.get("name"),
|
|
"gid": str(r.get("group_id") or "")[:8],
|
|
"biz": r.get("business_status"),
|
|
"push": r.get("is_pushing"),
|
|
"neko": r.get("neko_instance_id"),
|
|
"studio_on_air": snap.get("on_air"),
|
|
"studio_status": snap.get("live_status"),
|
|
"studio_prep": snap.get("preparing_stream"),
|
|
"studio_recv": snap.get("encoder_receiving"),
|
|
"studio_lost": snap.get("encoder_lost"),
|
|
"studio_src": snap.get("detect_source"),
|
|
"studio_age": snap.get("age_sec"),
|
|
})
|
|
print("RELAY_ACTIVE", json.dumps(push, ensure_ascii=False, indent=2))
|
|
|
|
inst = yn.list_instances(12, check_http=False)
|
|
running=[i for i in inst if i.get("running")]
|
|
print("NEKO_RUNNING", [(i.get("id"), i.get("status")) for i in running])
|
|
for i in running[:8]:
|
|
nid=int(i.get("id") or 0)
|
|
try:
|
|
sig=yn._cdp_studio_page_signals(nid, force=True, max_age_sec=0.0)
|
|
print("cdp", nid, json.dumps({k:sig.get(k) for k in (
|
|
"ok","live_status","on_air","preparing_stream","control_ready",
|
|
"encoder_receiving","encoder_lost","health","session_live"
|
|
)}, ensure_ascii=False))
|
|
except Exception as e:
|
|
print("cdp_err", nid, e)
|
|
PY
|
|
""",
|
|
)
|
|
c.close()
|
|
raise SystemExit(code)
|