douyinWEB/scripts/_neko7_open_studio.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

71 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
"""Open Studio Live URL on neko-7 after soft Chrome restart (signed-out state)."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
STUDIO = "https://studio.youtube.com/video/i6szUMA25RM/livestreaming"
REMOTE = r'''#!/bin/bash
set -uo pipefail
NAME=douyinweb-neko-7
STUDIO='__STUDIO__'
docker exec "$NAME" python3 - <<PY
import json, time, urllib.request, urllib.parse
url = "$STUDIO"
# open new tab
try:
req = urllib.request.Request("http://127.0.0.1:9222/json/new?" + urllib.parse.quote(url, safe=""), method="PUT")
with urllib.request.urlopen(req, timeout=10) as r:
print("new", r.read()[:200])
except Exception as e:
print("new_fail", e)
try:
with urllib.request.urlopen("http://127.0.0.1:9222/json/new?" + url, timeout=10) as r:
print("new2", r.read()[:200])
except Exception as e2:
print("new2_fail", e2)
time.sleep(4)
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read().decode())
print("tabs", len(tabs))
for t in tabs:
print("-", (t.get("title") or "")[:60], "|", (t.get("url") or "")[:150])
PY
echo OPEN_OK
'''.replace("__STUDIO__", STUDIO)
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=45,
banner_timeout=120,
allow_agent=False,
look_for_keys=False,
)
sftp = c.open_sftp()
with sftp.file("/tmp/_neko7_open.sh", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command(
f"echo '{PASS}' | sudo -S -p '' bash /tmp/_neko7_open.sh",
timeout=60,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())