douyinWEB/scripts/_diag_dylive_yt_long.py
2026-09-13 22:10:49 -05:00

121 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""Diagnose yt-long on dylive — read only."""
from __future__ import annotations
import json
import sys
import time
import urllib.request
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "107.173.30.245"
PASS = "Xiao4669805"
def ssh_run(c, cmd, timeout=60):
print(f"\n===== {cmd[:100]} =====", flush=True)
_i, o, e = c.exec_command(cmd, timeout=timeout)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
if out:
print(out[:12000], flush=True)
if err.strip():
print("[stderr]", err[:1500], flush=True)
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(HOST, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
break
except Exception as ex:
print("ssh fail", ex, flush=True)
time.sleep(1 + i)
else:
raise SystemExit("ssh_fail")
ssh_run(
c,
r"""
set -e
echo api=$(systemctl is-active douyinweb-api)
# settings keys related to yt long
sqlite3 /opt/douyinWEB/backend/data/monitor.db "SELECT key, substr(value,1,200) FROM settings WHERE key LIKE '%yt_long%' OR key LIKE '%ytlong%' OR key LIKE '%long%' ORDER BY key;" 2>/dev/null || \
python3 - <<'PY'
import sqlite3
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
cur=con.cursor()
for row in cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1"):
print('table', row[0])
PY
""",
)
ssh_run(
c,
r"""
python3 - <<'PY'
import sqlite3, json
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
con.row_factory=sqlite3.Row
cur=con.cursor()
tables=[r[0] for r in cur.execute("SELECT name FROM sqlite_master WHERE type='table'")]
print('tables', tables)
# find yt long related
for t in tables:
if 'yt' in t.lower() or 'long' in t.lower() or 'clip' in t.lower() or 'upload' in t.lower():
print('---', t)
try:
cols=[x[1] for x in cur.execute(f'PRAGMA table_info({t})')]
print('cols', cols)
n=cur.execute(f'SELECT COUNT(*) FROM {t}').fetchone()[0]
print('count', n)
rows=cur.execute(f'SELECT * FROM {t} ORDER BY rowid DESC LIMIT 8').fetchall()
for r in rows:
d=dict(r)
# trim
for k,v in list(d.items()):
if isinstance(v,str) and len(v)>120: d[k]=v[:120]+'...'
print(d)
except Exception as e:
print('err', e)
# settings
print('---settings yt/long/quota---')
try:
for r in cur.execute("SELECT key, value FROM settings WHERE key LIKE '%yt%' OR key LIKE '%long%' OR key LIKE '%quota%' OR key LIKE '%short%' ORDER BY key"):
v=r[1]
if isinstance(v,str) and len(v)>300: v=v[:300]+'...'
print(r[0], '=', v)
except Exception as e:
print('settings_err', e)
PY
""",
)
ssh_run(
c,
r"""
journalctl -u douyinweb-api --since '2 hours ago' --no-pager 2>/dev/null | grep -iE 'yt.?long|yt_long|long.?upload|upload.*long|quota|403|429' | tail -60
echo '---ffmpeg yt_long---'
pgrep -a ffmpeg 2>/dev/null | grep -i yt_long || echo none
ls -lt /opt/douyinWEB/backend/data/clips/yt_long 2>/dev/null | head -15 || echo no_dir
""",
)
# local API probe via ssh curl
ssh_run(
c,
r"""
curl -sS -m 15 http://127.0.0.1:8014/api/yt-long/status 2>/dev/null | head -c 4000; echo
curl -sS -m 15 http://127.0.0.1:8014/api/yt-long 2>/dev/null | head -c 2000; echo
curl -sS -m 15 'http://127.0.0.1:8014/openapi.json' 2>/dev/null | python3 -c "import sys,json; d=json.load(sys.stdin); print('\n'.join(sorted(p for p in d.get('paths',{}) if 'yt' in p.lower() or 'long' in p.lower())[:40]))" 2>/dev/null || true
""",
)
c.close()
print("DONE", flush=True)
if __name__ == "__main__":
main()