70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""CDP-read ops-neko-2 Studio DOM (nodata / 待开播) — read only."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
SCRIPT = r"""#!/bin/bash
|
|
set +e
|
|
N=douyinweb-ops-neko-2
|
|
docker exec -i "$N" python3 - <<'PY'
|
|
import json, re, urllib.request
|
|
tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=5).read())
|
|
live=[t for t in tabs if 'livestreaming' in (t.get('url') or '').lower()]
|
|
print('live_tabs', len(live))
|
|
for t in live[:3]:
|
|
print('URL', (t.get('url') or '')[:120])
|
|
# use existing scrape script if present
|
|
import subprocess, os
|
|
for p in ['/etc/neko/cdp_studio_scrape.py','/opt/neko/cdp_studio_scrape.py']:
|
|
if os.path.isfile(p):
|
|
print('scrape', p)
|
|
print(subprocess.check_output(['python3',p], text=True, timeout=20)[:2000])
|
|
break
|
|
else:
|
|
# inline minimal
|
|
import base64, socket, struct, time, os as _os
|
|
if not live:
|
|
print('no live'); raise SystemExit
|
|
ws=live[0].get('webSocketDebuggerUrl') or ''
|
|
# fallback: just print titles
|
|
print('ws', bool(ws))
|
|
PY
|
|
# also copy scrape from host if mounted
|
|
ls /opt/douyinWEB/backend/neko/cdp_studio_scrape.py 2>/dev/null
|
|
docker exec "$N" bash -lc 'test -f /etc/neko/cdp_studio_scrape.py && python3 /etc/neko/cdp_studio_scrape.py || true' 2>/dev/null | head -c 2500
|
|
"""
|
|
|
|
|
|
def main():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_probe_ops2_dom.sh", "w") as f:
|
|
f.write(SCRIPT)
|
|
# also upload scrape via stdin to docker
|
|
scrape = open(
|
|
r"c:\Users\admin\Desktop\douyinWEB\backend\neko\cdp_studio_scrape.py",
|
|
"rb",
|
|
).read()
|
|
with sftp.file("/tmp/cdp_studio_scrape.py", "wb") as f:
|
|
f.write(scrape)
|
|
sftp.close()
|
|
_i, o, e = c.exec_command(
|
|
"echo '4669805' | sudo -S -p '' bash -lc "
|
|
"'docker exec -i douyinweb-ops-neko-2 python3 - < /tmp/cdp_studio_scrape.py'",
|
|
timeout=60,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace")[:4000])
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|