douyinWEB/scripts/_probe_yt_live_auth.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

113 lines
3.7 KiB
Python

# -*- coding: utf-8 -*-
"""Auth-aware live-map probe + force refresh on physical."""
from __future__ import annotations
import json
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
REMOTE = r'''
import json, subprocess, urllib.request
# login cookie
import http.cookiejar
cj=http.cookiejar.CookieJar()
opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
# try status without auth
for path in ("/api/auth/status","/api/health","/api/youtube/live-map","/api/youtube/live-map?force=1"):
try:
req=urllib.request.Request("http://127.0.0.1:8014"+path)
with opener.open(req, timeout=60) as r:
body=r.read()[:500]
print(path, r.status, body[:200])
except Exception as e:
print(path, type(e).__name__, e)
# login
try:
data=json.dumps({"username":"hackrobot","password":"Xiao4669805@"}).encode()
req=urllib.request.Request("http://127.0.0.1:8014/api/auth/login", data=data, headers={"Content-Type":"application/json"})
with opener.open(req, timeout=30) as r:
print("login", r.status, r.read()[:200])
except Exception as e:
print("login err", e)
for path in ("/api/youtube/live-map","/api/youtube/live-map?force=1"):
try:
req=urllib.request.Request("http://127.0.0.1:8014"+path)
with opener.open(req, timeout=120) as r:
j=json.loads(r.read())
print(path, "live_count", j.get("live_count"), "source", j.get("source"), "svc_error", j.get("svc_error"), "refreshing", j.get("refreshing"))
live=[(k,v) for k,v in (j.get("entries") or {}).items() if v.get("is_live")]
print("live n", len(live))
for k,v in sorted(live)[:40]:
print(" ", k, v.get("title"), v.get("source"), v.get("assign_group_id"))
except Exception as e:
print(path, type(e).__name__, e)
# studio telemetry latest
print("\n=== studio telemetry ===")
try:
from pathlib import Path
p=Path("/opt/douyinWEB/backend/data/neko/studio_telemetry_latest.json")
if p.exists():
print(p.read_text(encoding="utf-8", errors="replace")[:1500])
else:
print("no latest file")
except Exception as e:
print(e)
# neko status via python
import os, sys
sys.path.insert(0,"/opt/douyinWEB/backend")
os.chdir("/opt/douyinWEB/backend")
try:
from app import youtube_neko as yn
evs=yn.list_studio_events(10) if hasattr(yn,"list_studio_events") else []
print("events", len(evs) if isinstance(evs,list) else evs)
for ev in (evs or [])[:5]:
print({k:ev.get(k) for k in ("neko_id","live_status","viewer_count","url","health","received_at","page_title") if k in ev or True})
except Exception as e:
print("neko import", type(e).__name__, e)
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=50,
banner_timeout=100,
allow_agent=False,
look_for_keys=False,
)
break
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2)
else:
raise SystemExit("ssh fail")
sftp = c.open_sftp()
with sftp.file("/tmp/_yt_live_auth_probe.py", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_yt_live_auth_probe.py", timeout=180)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
c.close()
if __name__ == "__main__":
main()