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>
97 lines
3.3 KiB
Python
97 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Probe physical YouTube live-map vs assign groups right now."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
PASS = "4669805"
|
|
|
|
REMOTE = r'''
|
|
import json, sqlite3, urllib.request
|
|
print("=== live-map local ===")
|
|
try:
|
|
raw=urllib.request.urlopen("http://127.0.0.1:8014/api/youtube/live-map", timeout=20).read()
|
|
j=json.loads(raw)
|
|
print("live_count", j.get("live_count"), "source", j.get("source"), "checked_at", j.get("checked_at"), "svc_error", j.get("svc_error"))
|
|
ents=j.get("entries") or {}
|
|
live=[(k,v) for k,v in ents.items() if v.get("is_live")]
|
|
print("live entries", len(live))
|
|
for k,v in sorted(live)[:30]:
|
|
print(k, {x:v.get(x) for x in ("title","source","assign_group_id","live_url","error")})
|
|
print("total entries", len(ents))
|
|
except Exception as e:
|
|
print("live-map err", type(e).__name__, e)
|
|
|
|
print("\n=== assign groups ===")
|
|
con=sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db")
|
|
con.row_factory=sqlite3.Row
|
|
for r in con.execute("SELECT id,name,channel_pk,youtube_channel_id,enabled,neko_instance_id FROM yt_assign_groups ORDER BY neko_instance_id"):
|
|
print(dict(r))
|
|
|
|
print("\n=== shorts with yt id (sample) ===")
|
|
for r in con.execute("SELECT id,name,youtube_channel_id,enabled FROM shorts_channels WHERE youtube_channel_id IS NOT NULL AND trim(youtube_channel_id)!='' LIMIT 20"):
|
|
print(dict(r))
|
|
|
|
print("\n=== youtube-svc health ===")
|
|
try:
|
|
raw=urllib.request.urlopen("http://127.0.0.1:8020/health", timeout=10).read()
|
|
print(raw[:300])
|
|
except Exception as e:
|
|
print("yt svc", type(e).__name__, e)
|
|
'''
|
|
|
|
|
|
def main():
|
|
print("=== public live-map ===", flush=True)
|
|
for url in (
|
|
"https://dy.nomadro.com/api/youtube/live-map",
|
|
"https://dy.nomadro.cn/api/youtube/live-map",
|
|
):
|
|
try:
|
|
r = httpx.get(url, timeout=30)
|
|
j = r.json()
|
|
print(url, r.status_code, "live_count", j.get("live_count"), "source", j.get("source"), flush=True)
|
|
live = [(k, v) for k, v in (j.get("entries") or {}).items() if v.get("is_live")]
|
|
for k, v in sorted(live)[:20]:
|
|
print(" ", k, v.get("title"), v.get("source"), v.get("assign_group_id"), flush=True)
|
|
except Exception as ex:
|
|
print(url, type(ex).__name__, ex, flush=True)
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=50,
|
|
banner_timeout=100,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2)
|
|
else:
|
|
raise SystemExit("ssh fail")
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_yt_live_probe.py", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_yt_live_probe.py", timeout=90)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|