#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Truth: live list vs probe vs relay for asian streetfood time_slot.""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=25, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_ts_truth.py", "w") as f: f.write( r""" import json, time, sqlite3, os, sys sys.path.insert(0, '/opt/douyinWEB/backend') os.chdir('/opt/douyinWEB/backend') from app import db from app import youtube_relay_pipeline as yrp from app import yt_assign_db from app import youtube_relay_db from app.douyin_live import check_room gid='3fb8cbf7-2180-45bc-99f0-836169f0bf97' g=yt_assign_db.get_group(gid) or {} print('group', g.get('name'), 'cat', g.get('category'), 'prefer', g.get('neko_open_prefer'), 'ops', g.get('ops_neko_slot')) # active slot? print('in_active_slot', yrp._group_in_active_slot(gid, keyed_only=True)) rooms=db.list_live_douyin_rooms_for_shorts(limit=40) print('LIVE_LIST_COUNT', len(rooms)) for i,r in enumerate(rooms[:12]): print(f" [{i}] rid={r.get('room_id')} anchor={r.get('last_anchor') or r.get('last_title')} url={str(r.get('url') or '')[:70]}") src=yrp.pick_source_for_group(g, respect_schedule=True) print('PICK', src) st=youtube_relay_db.get_relay_state(gid) or {} print('RELAY', {k:st.get(k) for k in ('status','error','source_url','source_room_id','anchor_name','ffmpeg_pid','push_seconds')}) log=st.get('recent_log') or [] if isinstance(log,str): try: log=json.loads(log) except: log=log.splitlines() print('LOG_TAIL') for ln in list(log)[-15:]: print(' ', ln) # probe current relay source AND first live list room cookie='' try: cookie=str(db.get_settings_map().get('douyin_cookie') or '') except Exception: pass targets=[] if st.get('source_url'): targets.append(('relay_src', st.get('source_url'))) if src and src.get('source_url'): targets.append(('pick_src', src.get('source_url'))) if rooms: targets.append(('live0', rooms[0].get('url'))) seen=set() for name,url in targets: if not url or url in seen: continue seen.add(url) try: import asyncio p=asyncio.get_event_loop().run_until_complete(check_room(url, cookie=cookie)) if False else None except Exception: p=None # sync wrapper? try: from app import douyin_live import asyncio p=asyncio.run(check_room(url, cookie=cookie)) except Exception as ex: print('PROBE_FAIL', name, type(ex).__name__, ex) continue print('PROBE', name, 'live', getattr(p,'live',None) or (p.get('live') if isinstance(p,dict) else None), 'status', getattr(p,'status',None) or (p.get('status') if isinstance(p,dict) else None), 'risk', getattr(p,'risk',None) if not isinstance(p,dict) else p.get('risk'), 'url', str(url)[:60]) if isinstance(p, dict): print(' keys', {k:p.get(k) for k in ('ok','live','status','anchor_name','flv','error') if k in p or True}) """ ) sftp.close() _, o, e = c.exec_command("cd /opt/douyinWEB/backend && .venv/bin/python /tmp/_ts_truth.py 2>&1 || python3 /tmp/_ts_truth.py 2>&1", timeout=90) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() if __name__ == "__main__": main()