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

75 lines
2.7 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r'''
import asyncio, os, sys, json
os.chdir("/opt/douyinWEB/backend"); sys.path.insert(0, ".")
from app import youtube_live, yt_assign_db, youtube_neko, youtube_client, db
GIDS = [
"e9bae7e8-ea13-4cf0-a96c-757069d662df",
"adeca103-800a-4cfb-b8eb-55375fe39fbc",
]
async def main():
youtube_live._LAST_OAUTH_AT = 0.0
# Direct probes
for gid in GIDS:
g = yt_assign_db.get_group(gid) or {}
cid = str(g.get("youtube_channel_id") or "")
pk = str(g.get("channel_pk") or "")
print("GROUP", g.get("name"), "cid", cid, "pk", pk)
url = f"https://www.youtube.com/channel/{cid}"
try:
bl = await youtube_client.batch_live([url])
r = (bl.get("results") or [{}])[0]
print(" youtubei", "is_live", r.get("is_live"), "err", r.get("error"), "src ok")
except Exception as ex:
print(" youtubei_err", ex)
try:
oa = await youtube_live._oauth_live_for_shorts(pk, cid)
print(" oauth", oa)
except Exception as ex:
print(" oauth_err", ex)
snap = youtube_neko.studio_snapshot_for_group(g, max_age_sec=180)
print(" studio", {k: snap.get(k) for k in ("on_air","encoder_receiving","encoder_lost","live_status","session_live","neko_ref","age_sec","detect_source")})
m = await youtube_live.build_live_map(force=True)
for gid in GIDS:
e = (m.get("entries") or {}).get(f"assign:{gid}") or {}
g = yt_assign_db.get_group(gid) or {}
cid = str(g.get("youtube_channel_id") or "")
pk = str(g.get("channel_pk") or "")
print("ENTRY assign", gid[:8], "is_live", e.get("is_live"), "source", e.get("source"), "err", e.get("error"))
print(" channel", (m.get("entries") or {}).get(f"channel:{cid}"))
print(" shorts", (m.get("entries") or {}).get(f"shorts:{pk}"))
print("live_count", m.get("live_count"))
asyncio.run(main())
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=30, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_dbg_phys_two.py", "w") as f:
f.write(REMOTE)
sftp.close()
cmd = "echo '4669805' | sudo -S -p '' /opt/douyinWEB/backend/.venv/bin/python /tmp/_dbg_phys_two.py"
_, o, e = c.exec_command(cmd, timeout=180)
print((o.read() + e.read()).decode("utf-8", "replace")[:5000])
c.close()
if __name__ == "__main__":
main()