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>
138 lines
4.9 KiB
Python
138 lines
4.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Reopen real Studio Live tabs + deploy URL-match fix. Close bogus accountchooser if needed."""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
PASS = "4669805"
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
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
|
|
install -m 644 /tmp/_fixurl_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
install -m 644 /tmp/_fixurl_scrape.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py
|
|
install -m 644 /tmp/_fixurl_ct.js /opt/douyinWEB/backend/neko/live-ops-extension/content.js
|
|
cd /opt/douyinWEB/backend && .venv/bin/python -m py_compile app/youtube_neko.py
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
|
|
python3 - <<'PY'
|
|
import json, subprocess
|
|
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
|
|
from urllib.parse import urlparse
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read().decode())
|
|
# close accountchooser / junk that embeds livestreaming in query
|
|
for t in tabs:
|
|
u=t.get("url") or ""
|
|
tid=t.get("id")
|
|
if not tid: continue
|
|
p=urlparse(u)
|
|
host=(p.netloc or "").lower()
|
|
if "accounts.google.com" in host or "signin" in u.lower():
|
|
try: urllib.request.urlopen(f"http://127.0.0.1:9222/json/close/{{tid}}", timeout=3).read()
|
|
except Exception: pass
|
|
# ensure real studio livestreaming tab
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read().decode())
|
|
live=[]
|
|
for t in tabs:
|
|
u=t.get("url") or ""
|
|
p=urlparse(u)
|
|
if (p.netloc or "").lower().endswith("studio.youtube.com") and "livestreaming" in (p.path or "").lower():
|
|
live.append(t)
|
|
if live:
|
|
print("ok_existing", live[0].get("url","")[:90])
|
|
else:
|
|
req=urllib.request.Request("http://127.0.0.1:9222/json/new?" + {url!r}, method="PUT")
|
|
body=urllib.request.urlopen(req, timeout=10).read().decode()
|
|
print("opened", body[:80])
|
|
'''
|
|
code, out = run(["docker", "exec", name, "python3", "-c", py], timeout=40)
|
|
print(name, (out or "").strip().splitlines()[-1] if out.strip() else "empty")
|
|
print("REOPEN_DONE")
|
|
PY
|
|
|
|
sleep 25
|
|
echo SCRAPE
|
|
python3 /tmp/_scrape_all_nekos.py
|
|
echo PROBE
|
|
/opt/douyinWEB/backend/.venv/bin/python /tmp/_probe_telemetry_detail.py
|
|
docker ps --filter name=douyinweb-neko- --format '{{.Names}} {{.Status}}'
|
|
"""
|
|
|
|
|
|
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()
|
|
mapping = [
|
|
("backend/app/youtube_neko.py", "_fixurl_neko.py"),
|
|
("backend/neko/cdp_studio_scrape.py", "_fixurl_scrape.py"),
|
|
("backend/neko/live-ops-extension/content.js", "_fixurl_ct.js"),
|
|
("scripts/_scrape_all_nekos.py", "_scrape_all_nekos.py"),
|
|
("scripts/_probe_telemetry_detail.py", "_probe_telemetry_detail.py"),
|
|
]
|
|
for rel, tmp in mapping:
|
|
with sftp.file(f"/tmp/{tmp}", "wb") as f:
|
|
f.write((ROOT / rel).read_bytes())
|
|
print("up", rel)
|
|
with sftp.file("/tmp/_fixurl_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_fixurl_deploy.sh", timeout=420)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|