176 lines
6.0 KiB
Python
176 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Why dy shows nomad vlog as live when user says not live — read only."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
|
|
|
|
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 e:
|
|
print(e, flush=True)
|
|
time.sleep(1 + i)
|
|
else:
|
|
raise SystemExit("ssh_fail")
|
|
|
|
cmd = r"""
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
import json, time
|
|
from app import yt_assign_db, youtube_neko, youtube_live
|
|
from app import db
|
|
|
|
# find nomad vlog groups
|
|
hits=[]
|
|
for g in yt_assign_db.list_groups(include_urls=True):
|
|
name=str(g.get('name') or '')
|
|
if 'nomad' in name.lower() and 'vlog' in name.lower():
|
|
hits.append(g)
|
|
elif str(g.get('youtube_channel_id') or '').find('nomad')>=0:
|
|
hits.append(g)
|
|
|
|
if not hits:
|
|
for g in yt_assign_db.list_groups(include_urls=False):
|
|
if int(g.get('neko_instance_id') or 0)==6:
|
|
hits.append(g)
|
|
|
|
print('hits', len(hits))
|
|
for g in hits:
|
|
gid=g.get('id')
|
|
ycid=str(g.get('youtube_channel_id') or g.get('channel_id') or '')
|
|
print('\n====', g.get('name'), gid, 'UC?', ycid)
|
|
print('neko', g.get('neko_instance_id'), 'enabled', g.get('neko_enabled'), 'category', g.get('category'))
|
|
# studio snap
|
|
snap=youtube_neko.studio_snapshot_for_group(g, max_age_sec=300)
|
|
print('STUDIO', json.dumps({k:snap.get(k) for k in [
|
|
'live_page_open','on_air','encoder_lost','session_live','live_status','viewer_count','health',
|
|
'url','age_sec','detect_source','ui_source','preparing_stream']}, ensure_ascii=False))
|
|
# relay state
|
|
try:
|
|
from app import youtube_relay_db
|
|
st=youtube_relay_db.get_relay_state(gid) or {}
|
|
print('RELAY', {k:st.get(k) for k in ('status','ffmpeg_pid','error','updated_at','is_pushing')})
|
|
except Exception as e:
|
|
print('relay_err', e)
|
|
# ffmpeg for this?
|
|
|
|
# public live probes
|
|
ids=[]
|
|
for g in hits:
|
|
for k in ('youtube_channel_id','channel_id'):
|
|
v=str(g.get(k) or '').strip()
|
|
if v.startswith('UC'):
|
|
ids.append(v)
|
|
ids=sorted(set(ids))
|
|
print('\nUC ids', ids)
|
|
if ids:
|
|
try:
|
|
batch=youtube_live.batch_channel_live(ids) if hasattr(youtube_live,'batch_channel_live') else None
|
|
print('batch_fn', type(batch))
|
|
except Exception as e:
|
|
print('batch_err', e)
|
|
# try common APIs
|
|
for fn_name in ['probe_channels_live','batch_is_live','youtubei_batch_live','fetch_live_map']:
|
|
fn=getattr(youtube_live, fn_name, None)
|
|
if callable(fn):
|
|
try:
|
|
r=fn(ids)
|
|
print(fn_name, json.dumps(r, ensure_ascii=False, default=str)[:1500])
|
|
except Exception as e:
|
|
print(fn_name, 'ERR', e)
|
|
|
|
# homepage / live-map style
|
|
try:
|
|
from app import main as app_main
|
|
except Exception:
|
|
pass
|
|
|
|
# search code paths used by assign cards
|
|
import sqlite3
|
|
con=sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
con.row_factory=sqlite3.Row
|
|
print('\n=== relay states for neko6 groups ===')
|
|
for r in con.execute("SELECT group_id,status,ffmpeg_pid,error,updated_at FROM yt_relay_states ORDER BY updated_at DESC LIMIT 20"):
|
|
print(dict(r))
|
|
|
|
print('\n=== ffmpeg ===')
|
|
import subprocess
|
|
out=subprocess.check_output(['bash','-lc',"pgrep -a ffmpeg | head -5 || true"], text=True)
|
|
print(out)
|
|
PY
|
|
|
|
# API endpoints the FE uses for card live badge
|
|
echo '=== openapi live paths ==='
|
|
curl -sS -m 10 http://127.0.0.1:8014/openapi.json | python3 -c "import sys,json; d=json.load(sys.stdin); print('\n'.join(sorted(p for p in d.get('paths',{}) if 'live' in p.lower() or 'assign' in p.lower())[:50]))"
|
|
|
|
# login + fetch assign overview / live map if any
|
|
python3 - <<'PY'
|
|
import json,urllib.request,http.cookiejar
|
|
cj=http.cookiejar.CookieJar()
|
|
op=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
req=urllib.request.Request('http://127.0.0.1:8014/api/auth/login', data=json.dumps({'username':'hackrobot','password':'Xiao4669805@'}).encode(), headers={'Content-Type':'application/json'}, method='POST')
|
|
print('login', op.open(req, timeout=20).read()[:80])
|
|
for path in [
|
|
'/api/youtube/assign/groups',
|
|
'/api/youtube/live/map',
|
|
'/api/youtube/assign/live-map',
|
|
'/api/ops/live-map',
|
|
'/api/youtube/relay/status',
|
|
]:
|
|
try:
|
|
r=op.open('http://127.0.0.1:8014'+path, timeout=30)
|
|
body=r.read().decode('utf-8','replace')
|
|
print('\nPATH', path, 'len', len(body))
|
|
# find nomad
|
|
if 'nomad' in body.lower() or 'LIVE' in body:
|
|
# try parse
|
|
try:
|
|
d=json.loads(body)
|
|
except Exception:
|
|
print(body[:500]); continue
|
|
# walk for nomadvlog-ish
|
|
def walk(x, path=''):
|
|
if isinstance(x, dict):
|
|
name=str(x.get('name') or x.get('title') or '')
|
|
if 'nomad' in name.lower() and 'vlog' in name.lower():
|
|
keys=['name','is_live','live','on_air','status','yt_live','channel_live','receiving','studio','neko']
|
|
print('CARD', {k:x.get(k) for k in keys if k in x or True})
|
|
print('FULL_KEYS', sorted(x.keys())[:60])
|
|
# print live-related fields
|
|
for k,v in x.items():
|
|
if any(t in k.lower() for t in ('live','air','receiv','push','status','studio','viewer')):
|
|
print(' ', k, '=', str(v)[:200])
|
|
for k,v in x.items():
|
|
walk(v, path+'.'+k)
|
|
elif isinstance(x, list):
|
|
for i,v in enumerate(x[:200]):
|
|
walk(v, path+f'[{i}]')
|
|
walk(d)
|
|
except Exception as e:
|
|
print('PATH', path, e)
|
|
PY
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=120)
|
|
print(o.read().decode("utf-8", "replace"), flush=True)
|
|
err = e.read().decode("utf-8", "replace")
|
|
if err.strip():
|
|
print("[stderr]", err[:2000], flush=True)
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|