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>
90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy time-slot mode for YouTube relay."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
REPO = "/opt/douyinWEB"
|
|
|
|
FILES = [
|
|
"backend/app/db.py",
|
|
"backend/app/yt_assign_db.py",
|
|
"backend/app/youtube_neko.py",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"backend/app/main.py",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
]
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
sftp.put(str(ROOT / rel), f"{REPO}/{rel}")
|
|
print("uploaded", rel)
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -e
|
|
systemctl restart douyinweb-api
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl restart douyinweb-web
|
|
sleep 3
|
|
systemctl is-active douyinweb-api douyinweb-web
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
from app.db import init_db, get_settings_map, update_settings_map
|
|
from app import yt_assign_db
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline as pipe, pick_source_for_group, _time_slot_mode
|
|
from app import youtube_neko
|
|
|
|
init_db()
|
|
cfg = get_settings_map()
|
|
print("time_slot_default", cfg.get("youtube_relay_time_slot_mode"))
|
|
assert hasattr(pipe, "set_time_slot_mode")
|
|
assert hasattr(youtube_neko, "wait_instance_ready_for_live")
|
|
|
|
# keyed schedule smoke
|
|
sched = yt_assign_db.build_rotation_schedule(include_urls=False, keyed_only=True)
|
|
print("keyed_schedule", sched.get("channel_count"), "slot_h", sched.get("slot_hours"), "active", [c.get("name") for c in (sched.get("channels") or []) if c.get("active")])
|
|
|
|
# toggle on then off for smoke
|
|
st = __import__("asyncio").get_event_loop().run_until_complete(pipe.set_time_slot_mode(True))
|
|
print("on", st.get("settings", {}).get("youtube_relay_time_slot_mode"), "exclusive", st.get("settings", {}).get("youtube_relay_exclusive_live"))
|
|
groups = yt_assign_db.list_groups(featured_only=True)
|
|
keyed = [g for g in groups if g.get("enabled") and (g.get("has_stream_key") or str(g.get("stream_key") or "").strip())]
|
|
print("keyed_groups", [(g.get("name"), g.get("neko_instance_id")) for g in keyed])
|
|
if keyed:
|
|
src = pick_source_for_group(keyed[0], respect_schedule=False, time_slot_mode=True)
|
|
print("live_source", (src or {}).get("room_id"), (src or {}).get("anchor_name"))
|
|
st2 = __import__("asyncio").get_event_loop().run_until_complete(pipe.set_time_slot_mode(False))
|
|
print("off", st2.get("settings", {}).get("youtube_relay_time_slot_mode"))
|
|
PY
|
|
"""
|
|
print("remote deploy…")
|
|
stdin, stdout, stderr = c.exec_command(cmd, timeout=360)
|
|
out = stdout.read().decode("utf-8", "replace")
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
code = stdout.channel.recv_exit_status()
|
|
print(out[-4000:] if len(out) > 4000 else out)
|
|
if err.strip():
|
|
print("STDERR:", err[-2000:])
|
|
print("exit", code)
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|