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>
107 lines
3.7 KiB
Python
107 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Reopen Studio Live URLs after accidental CDP close — PUT /json/new."""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
PASS = "4669805"
|
|
|
|
# Last known good Control Room URLs from probe (pre-close).
|
|
URLS = {
|
|
1: "https://studio.youtube.com/video/9tMkUp0iUH8/livestreaming",
|
|
2: "https://studio.youtube.com/video/zHthtNjrbeo/livestreaming",
|
|
3: "https://studio.youtube.com/video/8NeMVAjx0r4/livestreaming",
|
|
4: "https://studio.youtube.com/video/-kkCblUC8XM/livestreaming",
|
|
5: "https://studio.youtube.com/video/31s_VgR215k/livestreaming",
|
|
6: "https://studio.youtube.com/video/IKGJwKAZGWM/livestreaming",
|
|
7: "https://studio.youtube.com/video/i6szUMA25RM/livestreaming",
|
|
}
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
python3 - <<'PY'
|
|
import json, subprocess, urllib.parse
|
|
|
|
URLS = {
|
|
1: "https://studio.youtube.com/video/9tMkUp0iUH8/livestreaming",
|
|
2: "https://studio.youtube.com/video/zHthtNjrbeo/livestreaming",
|
|
3: "https://studio.youtube.com/video/8NeMVAjx0r4/livestreaming",
|
|
4: "https://studio.youtube.com/video/-kkCblUC8XM/livestreaming",
|
|
5: "https://studio.youtube.com/video/31s_VgR215k/livestreaming",
|
|
6: "https://studio.youtube.com/video/IKGJwKAZGWM/livestreaming",
|
|
7: "https://studio.youtube.com/video/i6szUMA25RM/livestreaming",
|
|
}
|
|
|
|
def run(cmd, timeout=30):
|
|
p = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
return p.returncode, (p.stdout or "") + (p.stderr or "")
|
|
|
|
for idx, url in URLS.items():
|
|
name = f"douyinweb-neko-{idx}"
|
|
py = f'''
|
|
import json, urllib.request
|
|
url = {url!r}
|
|
req = urllib.request.Request("http://127.0.0.1:9222/json/new?" + url, method="PUT")
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=10) as r:
|
|
body = r.read().decode()
|
|
print(json.dumps({{"ok": True, "body": body[:200]}}))
|
|
except Exception as e:
|
|
# fallback GET
|
|
try:
|
|
with urllib.request.urlopen("http://127.0.0.1:9222/json/new?" + url, timeout=10) as r:
|
|
body = r.read().decode()
|
|
print(json.dumps({{"ok": True, "via": "GET", "body": body[:200]}}))
|
|
except Exception as e2:
|
|
print(json.dumps({{"ok": False, "error": str(e), "error2": str(e2)}}))
|
|
'''
|
|
code, out = run(["docker", "exec", name, "python3", "-c", py], timeout=25)
|
|
print(name, (out or "").strip().splitlines()[-1] if out.strip() else "empty")
|
|
|
|
print("REOPEN_DONE")
|
|
# verify live tabs
|
|
for idx in URLS:
|
|
name = f"douyinweb-neko-{idx}"
|
|
py = "import json,urllib.request; tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=4).read().decode()); live=[t.get('url') for t in tabs if 'livestreaming' in (t.get('url') or '')]; print(len(live), (live[0][:80] if live else '-'))"
|
|
code, out = run(["docker", "exec", name, "python3", "-c", py], timeout=15)
|
|
print("check", name, out.strip())
|
|
PY
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__)
|
|
time.sleep(2)
|
|
else:
|
|
return 1
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_reopen_studio.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_reopen_studio.sh", timeout=180)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|