#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Read relay DB + stream key + kill loop evidence on dy (no API auth).""" from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") REMOTE = r''' cd /opt/douyinWEB/backend .venv/bin/python <<'PY' import json, time, sqlite3, os from pathlib import Path from app import db, yt_assign_db, youtube_relay_db, youtube_neko gid = "23fb62dd-fd66-402b-983a-a4d8d09397af" g = yt_assign_db.get_group(gid) or {} print("name", g.get("name")) print("yt_channel", g.get("youtube_channel_id")) print("stream_key_suffix", str(g.get("stream_key") or g.get("youtube_stream_key") or "")[-8:]) # key fields vary for k in sorted(g.keys()): if "key" in k.lower() or "rtmp" in k.lower() or "stream" in k.lower(): v = g.get(k) if isinstance(v, str) and len(v) > 12: print(f" field {k}=…{v[-12:]} len={len(v)}") else: print(f" field {k}={v}") st = youtube_relay_db.get_relay_state(gid) or {} print("status", st.get("status"), "pid", st.get("ffmpeg_pid"), "err", (st.get("error") or "")[:240]) print("started_at_age", round(time.time()-float(st.get("started_at") or 0),1) if st.get("started_at") else None) logs = st.get("recent_log") or [] if isinstance(logs, str): logs = logs.splitlines() print("=== FULL recent_log ===") for x in logs: print(x) snap = youtube_neko.studio_on_air_lookup(8, max_age_sec=30) print("STUDIO", json.dumps({k:snap.get(k) for k in ("live_status","on_air","encoder_receiving","health","url","age_sec","viewer_count","detect_source")}, ensure_ascii=False)) # history table if any conn = db.connect() cur = conn.cursor() for table in ("youtube_relay_state","relay_sessions","yt_relay_events","youtube_relay_log"): try: cur.execute(f"select name from sqlite_master where type='table' and name=?", (table,)) if cur.fetchone(): print("TABLE", table) except Exception as e: print("t", table, e) try: cur.execute("select id, group_id, status, reason, started_at, ended_at, substr(cast(metadata as text),1,120) from relay_sessions where group_id=? order by rowid desc limit 8", (gid,)) rows = cur.fetchall() print("relay_sessions rows", len(rows)) for r in rows: print(" ", r) except Exception as e: print("sessions_err", e) # list columns try: cur.execute("pragma table_info(relay_sessions)") print("cols", cur.fetchall()) cur.execute("select * from relay_sessions where group_id=? order by rowid desc limit 3", (gid,)) print(cur.fetchall()) except Exception as e2: print(e2) conn.close() # ffmpeg alive? import subprocess out = subprocess.check_output(["bash","-lc","ps -eo pid,etime,cmd | grep -E '[f]fmpeg.*rtmps' | head -5"], text=True) print("FFMPEG\n", out) PY ''' c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False) _, o, e = c.exec_command(REMOTE, timeout=60) print((o.read() + e.read()).decode("utf-8", "replace")) c.close()