douyinWEB/scripts/_probe_after_cdp_poller.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

87 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
"""Probe live-map + studio snapshots after CDP poller deploy."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
PY = r'''
import json, urllib.request, inspect, asyncio
from app import youtube_neko as yn, youtube_live
print("=== force live_map ===")
m = youtube_live.build_live_map(force=True)
if inspect.iscoroutine(m):
m = asyncio.run(m)
print("live_count", m.get("live_count"))
ents = m.get("entries") or {}
for k,v in sorted(ents.items()):
if v.get("is_live") or (isinstance(v.get("studio"), dict) and v["studio"].get("on_air")):
st = v.get("studio") or {}
print(k, "live", v.get("is_live"), "src", v.get("source"),
"studio_on_air", st.get("on_air"), "viewers", st.get("viewer_count"),
"ds", st.get("detect_source"))
print("=== http live-map ===")
raw = urllib.request.urlopen("http://127.0.0.1:8014/api/youtube/live-map", timeout=25).read().decode()
d = json.loads(raw)
print("top_keys", sorted(d.keys()))
print("live_count", d.get("live_count"))
ents = d.get("entries") or {}
for k,v in sorted(ents.items()):
if isinstance(v, dict) and v.get("is_live"):
print("http", k, "src", v.get("source"), "title", (v.get("title") or "")[:40])
print("=== on_air lookup ===")
for nid in range(1,8):
s = yn.studio_on_air_lookup(nid, max_age_sec=120)
print(nid, "page", s.get("live_page_open"), "on_air", s.get("on_air"),
"status", s.get("live_status"), "viewers", s.get("viewer_count"),
"src", s.get("detect_source"), "mins", len(s.get("minute_reports") or []))
'''
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(10):
try:
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=60,
banner_timeout=120,
allow_agent=False,
look_for_keys=False,
)
break
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2)
else:
return 1
sftp = c.open_sftp()
with sftp.file("/tmp/_probe_cdp_live.py", "w") as f:
f.write(PY)
sftp.close()
_, o, e = c.exec_command(
f"echo '{PASS}' | sudo -S -p '' bash -lc "
f"'cd /opt/douyinWEB/backend && PYTHONPATH=/opt/douyinWEB/backend "
f".venv/bin/python /tmp/_probe_cdp_live.py'",
timeout=180,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())