#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Debug youtubei batch_live for assign UC ids on both hosts.""" from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") REMOTE = r''' import asyncio, os, sys os.chdir("/opt/douyinWEB/backend") sys.path.insert(0, ".") from app import youtube_client from app.config import settings URLS = [ "https://www.youtube.com/channel/UCXFErW9DeE8EXrInlnyCnVw", # asian streetfood (phys live?) "https://www.youtube.com/channel/UCYnwXkCMmVFf8Vr6MlWb-Jw", # hackrobotlite "https://www.youtube.com/channel/UCjQ8jnBm2N4FGRowNXcXThw", # asian streetfood timeslot ] async def main(): print("DY_YOUTUBE_SVC_URL", getattr(settings, "youtube_svc_url", None)) try: print("health", await youtube_client.health()) except Exception as ex: print("health_err", ex) try: data = await youtube_client.batch_live(URLS) print("ok", data.get("ok"), "n", len(data.get("results") or [])) for r in data.get("results") or []: live = r.get("live") if isinstance(r.get("live"), dict) else {} print( " is_live=", r.get("is_live"), "cid=", r.get("channel_id"), "err=", str(r.get("error") or "")[:80], "title=", str(live.get("title") or r.get("title") or "")[:40], "url=", str(live.get("url") or "")[:60], "input=", str(r.get("input") or "")[-40:], ) except Exception as ex: print("batch_err", type(ex).__name__, ex) # single try: one = await youtube_client.channel_live(URLS[0]) print("channel_live0", one) except Exception as ex: print("channel_live_err", type(ex).__name__, ex) asyncio.run(main()) ''' def one(label, host, port, user, pw, sudo=False): print(f"\n##### {label} #####") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, port, user, pw, timeout=30, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_dbg_yt.py", "w") as f: f.write(REMOTE) sftp.close() # also show unit / curl extra = ( "systemctl is-active douyinweb-yt; " "systemctl show douyinweb-yt -p Environment -p ExecStart --no-pager | head -5; " "curl -sS -m 3 http://127.0.0.1:3100/health 2>/dev/null | head -c 120; echo; " "curl -sS -m 3 http://127.0.0.1:3001/health 2>/dev/null | head -c 120; echo; " "ss -lntp | grep -E '3100|3001|8099|4015' | head; " "grep -E 'YOUTUBE_SVC|youtube_svc' /opt/douyinWEB/backend/.env /etc/systemd/system/douyinweb-api.service.d/* 2>/dev/null | head -20" ) cmd = f"bash -lc '{extra}'" if sudo: cmd = f"echo '{pw}' | sudo -S -p '' bash -lc \"{extra}\"" _, o, e = c.exec_command(cmd, timeout=30) print((o.read() + e.read()).decode("utf-8", "replace")[:1500]) py = "/opt/douyinWEB/backend/.venv/bin/python /tmp/_dbg_yt.py" if sudo: py = f"echo '{pw}' | sudo -S -p '' {py}" _, o, e = c.exec_command(py, timeout=120) print((o.read() + e.read()).decode("utf-8", "replace")[:3000]) c.close() def main(): one("VPS", "107.173.30.245", 22, "root", "Xiao4669805", False) one("PHYS", "107.173.30.245", 4014, "eric", "4669805", True) if __name__ == "__main__": main()