# -*- coding: utf-8 -*- """Deep fix: YT svc health, PB/S3, shorts 9ch both hosts.""" from __future__ import annotations import json import sys import time import http.cookiejar import urllib.request import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") def call(base, path, opener=None, method="GET", body=None, timeout=40): data = None if body is None else json.dumps(body).encode() req = urllib.request.Request( f"{base}{path}", data=data, method=method, headers={"Content-Type": "application/json"}, ) op = opener or urllib.request.build_opener() with op.open(req, timeout=timeout) as r: return json.loads(r.read().decode()) def login(base): cj = http.cookiejar.CookieJar() op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) call(base, "/api/auth/login", op, "POST", {"username": "hackrobot", "password": "Xiao4669805@"}) return op def ssh(host, port, user, pw, sudo=False): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False) def run(cmd, t=120): if sudo: cmd = f"echo '{pw}' | sudo -S -p '' bash -lc {repr(cmd)}" _, o, e = c.exec_command(cmd, timeout=t) return (o.read() + e.read()).decode("utf-8", "replace") return c, run # Public API truth for base in ["https://dylive.nomadro.com", "https://dy.nomadro.com"]: print(f"\n===== API {base} =====") op = login(base) ytmon = call(base, "/api/youtube-monitor/status", op) print("youtube_svc", json.dumps(ytmon.get("youtube_svc"), ensure_ascii=False)[:400]) print("yt_monitor running", ytmon.get("running"), "enabled", ytmon.get("yt_monitor_enabled")) shorts = call(base, "/api/shorts/status", op) print( "shorts", { k: shorts.get(k) for k in ( "enabled", "running", "quota_gap", "processed", "sampled", "last_error", "yt_quota", ) }, ) ch = call(base, "/api/shorts/channels", op) rows = ch.get("channels") or ch.get("items") or ch if isinstance(rows, list): print("shorts_channels", len(rows)) for r in rows[:12]: if isinstance(r, dict): print( " ", r.get("id") or r.get("channel_id"), (r.get("title") or r.get("name") or "")[:40], "enabled", r.get("enabled"), ) relay = call(base, "/api/youtube/relay/status", op) print( "relay", { k: relay.get(k) for k in ("enabled", "running", "pushing_count", "enabled_groups", "last_error") }, ) try: live = call(base, "/api/youtube/live-map", op, timeout=90) print("live_map", live.get("live_count"), live.get("source"), "entries", len(live.get("entries") or {})) except Exception as ex: print("live_map ERR", ex) # VPS deep print("\n===== VPS fix probe =====") c, run = ssh("107.173.30.245", 22, "root", "Xiao4669805") print(run("free -h; uptime; systemctl is-active douyinweb-pb douyinweb-s3 douyinweb-yt douyinweb-api douyinweb-web")) print(run("systemctl status douyinweb-pb --no-pager -l | head -35")) print(run("systemctl status douyinweb-s3 --no-pager -l | head -25")) print(run("curl -sS -m 5 http://127.0.0.1:8020/health; echo; curl -sS -m 5 http://127.0.0.1:8092/api/health 2>&1 | head -c 200; echo")) print(run("ls -la /opt/douyinWEB/pb/ | head; file /opt/douyinWEB/pb/pocketbase 2>/dev/null; systemctl cat douyinweb-pb | head -40")) print(run( "python3 -c \"import sqlite3; c=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db'); " "print([(k,c.execute('select value from app_settings where key=?',(k,)).fetchone() or c.execute('select value from settings where key=?',(k,)).fetchone()) " "for k in ['shorts_enabled','youtube_relay_enabled','yt_long_enabled']])\"" )) # find settings table print(run( "python3 - <<'PY'\n" "import sqlite3\n" "con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')\n" "print(con.execute(\"select name from sqlite_master where type='table'\").fetchall())\n" "for t in con.execute(\"select name from sqlite_master where type='table'\").fetchall():\n" " n=t[0]\n" " if 'setting' in n.lower() or 'short' in n.lower():\n" " print('TABLE', n, con.execute(f'pragma table_info({n})').fetchall()[:8])\n" "PY" )) c.close() c2, run2 = ssh("107.173.30.245", 4014, "eric", "4669805", sudo=True) print("\n===== PHYS probe =====") print(run2("free -h; systemctl is-active douyinweb-pb douyinweb-s3 douyinweb-yt douyinweb-api douyinweb-web")) print(run2("curl -sS -m 5 http://127.0.0.1:8020/health; echo")) print(run2("systemctl status douyinweb-pb --no-pager -l | head -30")) c2.close()