141 lines
4.5 KiB
Python
141 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Compare live FFmpeg inputs on both VPS — same source claim."""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import sys
|
|
import time
|
|
import urllib.parse
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOSTS = [("dylive", "107.173.30.245"), ("dy", "108.174.50.68")]
|
|
PASS = "Xiao4669805"
|
|
|
|
SCRIPT = r"""
|
|
set +e
|
|
echo '=== ffmpeg procs ==='
|
|
ps -eo pid,pcpu,pmem,etime,cmd | grep '[f]fmpeg' | head -5
|
|
echo
|
|
echo '=== parse input url ==='
|
|
python3 - <<'PY'
|
|
import subprocess, re, urllib.parse
|
|
out=subprocess.check_output(['ps','-eo','args'], text=True, errors='replace')
|
|
for line in out.splitlines():
|
|
if 'ffmpeg' not in line or 'rtmps://' not in line: continue
|
|
if line.strip().startswith('grep'): continue
|
|
# input after -i
|
|
m=re.search(r'-i\s+(\S+)', line)
|
|
vin=m.group(1).strip('"') if m else ''
|
|
# output rtmps
|
|
mo=re.search(r'(rtmps://\S+)', line)
|
|
vout=mo.group(1) if mo else ''
|
|
# scale
|
|
ms=re.search(r'scale=([^:\\s]+)', line)
|
|
scale=ms.group(1) if ms else ''
|
|
mb=re.search(r'-b:v\s+(\S+)', line)
|
|
br=mb.group(1) if mb else ''
|
|
mt=re.search(r'-threads\s+(\S+)', line)
|
|
th=mt.group(1) if mt else ''
|
|
print('INPUT', vin[:220])
|
|
# classify
|
|
low=vin.lower()
|
|
kind='unknown'
|
|
for k in ('uhd','origin','hd','sd','ld','md','_or4','_hd','_sd','_ld'):
|
|
if k in low: kind=k; break
|
|
# unique_id / stream id
|
|
qs=urllib.parse.urlparse(vin)
|
|
q=urllib.parse.parse_qs(qs.query)
|
|
print('host', qs.hostname)
|
|
print('path', qs.path[-80:])
|
|
print('unique_id', (q.get('unique_id') or [''])[0][:120])
|
|
print('kind_hint', kind)
|
|
print('scale', scale, 'b:v', br, 'threads', th)
|
|
print('OUT', vout[:100])
|
|
print('CPU_LINE_has_uhd', '_uhd' in vin or 'uhd' in vin.lower())
|
|
PY
|
|
echo
|
|
echo '=== relay status brief ==='
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app.db import _connect, _lock
|
|
import json
|
|
with _lock:
|
|
conn=_connect()
|
|
try:
|
|
rows=conn.execute("SELECT group_id, status, substr(source_url,1,120), substr(coalesce(last_error,''),1,60) FROM yt_relay_states WHERE status LIKE '%push%' OR status LIKE '%live%' OR is_pushing=1 LIMIT 10").fetchall()
|
|
except Exception:
|
|
try:
|
|
cols=[r[1] for r in conn.execute('PRAGMA table_info(yt_relay_states)').fetchall()]
|
|
print('relay_cols', cols)
|
|
rows=conn.execute('SELECT * FROM yt_relay_states LIMIT 5').fetchall()
|
|
for r in rows: print(dict(r))
|
|
rows=[]
|
|
except Exception as e:
|
|
print('err', e); rows=[]
|
|
for r in rows:
|
|
print('relay', r)
|
|
# groups currently pushing via names
|
|
try:
|
|
for r in conn.execute("SELECT name, neko_instance_id, neko_enabled FROM yt_assign_groups").fetchall():
|
|
pass
|
|
except Exception: pass
|
|
PY
|
|
# from API local
|
|
curl -sS -m 8 http://127.0.0.1:8014/api/youtube/relay/status 2>/dev/null | python3 - <<'PY'
|
|
import sys,json
|
|
raw=sys.stdin.read()
|
|
try:
|
|
d=json.loads(raw)
|
|
except Exception as e:
|
|
print('json_fail', e, raw[:200]); raise SystemExit
|
|
entries=d.get('entries') or d.get('groups') or d.get('items') or []
|
|
if isinstance(d, dict) and not entries:
|
|
# maybe {group_id: {...}}
|
|
if all(isinstance(v, dict) for v in d.values()):
|
|
entries=[{'group_id':k, **v} for k,v in d.items() if isinstance(v, dict)]
|
|
print('keys', list(d.keys())[:20])
|
|
if isinstance(entries, list):
|
|
for e in entries[:12]:
|
|
if not isinstance(e, dict):
|
|
continue
|
|
pushing=e.get('is_pushing') or e.get('pushing') or (str(e.get('status') or '').lower() in ('pushing','live','on_air'))
|
|
src=str(e.get('source_url') or e.get('douyin_url') or e.get('input_url') or '')[:100]
|
|
name=e.get('name') or e.get('group_name') or e.get('title') or ''
|
|
if pushing or src:
|
|
print({
|
|
'name': str(name)[:40],
|
|
'pushing': pushing,
|
|
'status': e.get('status') or e.get('phase'),
|
|
'src': src,
|
|
'fps': e.get('fps') or e.get('ffmpeg_fps'),
|
|
'bitrate': e.get('bitrate') or e.get('speed'),
|
|
})
|
|
PY
|
|
echo HOST_DONE
|
|
"""
|
|
|
|
|
|
def connect(host):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(host, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", host, e, flush=True)
|
|
time.sleep(2)
|
|
raise SystemExit("ssh fail")
|
|
|
|
|
|
for label, host in HOSTS:
|
|
print(f"\n######## {label} {host} ########", flush=True)
|
|
c = connect(host)
|
|
_i, o, e = c.exec_command(SCRIPT, timeout=60)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
print("ALL_DONE", flush=True)
|