187 lines
5.9 KiB
Python
187 lines
5.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Read-only check of two time_slot channels before auto-relay test."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import http.cookiejar
|
|
import urllib.request
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def api(base: str):
|
|
cj = http.cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
login = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
op.open(
|
|
urllib.request.Request(
|
|
base + "/api/auth/login",
|
|
data=login,
|
|
method="POST",
|
|
headers={"Content-Type": "application/json"},
|
|
),
|
|
timeout=30,
|
|
)
|
|
|
|
def get(path: str):
|
|
with op.open(urllib.request.Request(base + path), timeout=60) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
print(f"\n===== {base} =====")
|
|
groups = get("/api/youtube/assign/groups")
|
|
rows = groups.get("groups") or groups if isinstance(groups, list) else groups.get("groups") or []
|
|
targets = []
|
|
for g in rows:
|
|
name = str(g.get("name") or "")
|
|
if "asian streetfood" in name.lower() or name.lower() == "nomadro" or "nomadro" == name.lower():
|
|
if str(g.get("category") or "") == "time_slot" or "asian" in name.lower() or name.lower() == "nomadro":
|
|
targets.append(g)
|
|
# also match by handle-ish
|
|
if not targets:
|
|
for g in rows:
|
|
n = str(g.get("name") or "").lower()
|
|
if "asian" in n or n == "nomadro":
|
|
targets.append(g)
|
|
|
|
# de-dupe
|
|
seen = set()
|
|
uniq = []
|
|
for g in targets:
|
|
gid = str(g.get("id") or "")
|
|
if gid in seen:
|
|
continue
|
|
seen.add(gid)
|
|
uniq.append(g)
|
|
|
|
print("matched", len(uniq))
|
|
for g in uniq:
|
|
print(
|
|
"-",
|
|
g.get("name"),
|
|
"id=",
|
|
g.get("id"),
|
|
"cat=",
|
|
g.get("category"),
|
|
"armed=",
|
|
g.get("time_slot_armed"),
|
|
"neko=",
|
|
g.get("neko_instance_id"),
|
|
"neko_en=",
|
|
g.get("neko_enabled"),
|
|
"prefer=",
|
|
g.get("neko_open_prefer"),
|
|
"key=",
|
|
bool(g.get("has_stream_key") or g.get("stream_key")),
|
|
"pool=",
|
|
len(g.get("pool") or []),
|
|
"feat=",
|
|
len(g.get("featured") or []),
|
|
"slots=",
|
|
len(g.get("slots") or []),
|
|
"oauth_profile=",
|
|
g.get("oauth_profile_id"),
|
|
)
|
|
|
|
try:
|
|
sch = get("/api/youtube/assign/schedule")
|
|
print(
|
|
"schedule mode=",
|
|
sch.get("time_slot_mode"),
|
|
"now=",
|
|
sch.get("now_label"),
|
|
"channels=",
|
|
sch.get("channel_count"),
|
|
)
|
|
for ch in sch.get("channels") or []:
|
|
nm = str(ch.get("name") or "")
|
|
if "asian" in nm.lower() or nm.lower() == "nomadro":
|
|
print(
|
|
" slot",
|
|
nm,
|
|
"active=",
|
|
ch.get("active"),
|
|
ch.get("start_label"),
|
|
"-",
|
|
ch.get("end_label"),
|
|
"group=",
|
|
ch.get("group_id"),
|
|
)
|
|
except Exception as e:
|
|
print("schedule ERR", e)
|
|
|
|
try:
|
|
st = get("/api/youtube/relay/status")
|
|
print(
|
|
"relay auto=",
|
|
st.get("auto_enabled") or st.get("settings", {}).get("youtube_relay_auto"),
|
|
"running=",
|
|
st.get("running"),
|
|
"rows=",
|
|
len(st.get("rows") or st.get("monitors") or []),
|
|
)
|
|
for row in st.get("rows") or st.get("monitors") or []:
|
|
nm = str(row.get("channel_name") or row.get("name") or "")
|
|
gid = str(row.get("group_id") or "")
|
|
if gid in seen or "asian" in nm.lower() or "nomadro" in nm.lower():
|
|
print(
|
|
" mon",
|
|
nm or gid,
|
|
"biz=",
|
|
row.get("business_status"),
|
|
"push=",
|
|
row.get("is_pushing") or row.get("pushing"),
|
|
"neko_run=",
|
|
(row.get("neko") or {}).get("running"),
|
|
"studio=",
|
|
((row.get("neko") or {}).get("studio") or {}).get("on_air"),
|
|
"err=",
|
|
(row.get("last_error") or row.get("error") or "")[:80],
|
|
)
|
|
except Exception as e:
|
|
print("relay status ERR", e)
|
|
|
|
try:
|
|
settings = get("/api/settings")
|
|
cfg = settings.get("settings") or settings
|
|
keys = [
|
|
"youtube_relay_auto",
|
|
"youtube_relay_enabled",
|
|
"youtube_auto_relay",
|
|
"yt_relay_auto",
|
|
]
|
|
for k in keys:
|
|
if k in cfg:
|
|
print("setting", k, "=", cfg.get(k))
|
|
# print any youtube_relay*
|
|
for k, v in sorted(cfg.items()):
|
|
if "relay" in k.lower() and "youtube" in k.lower():
|
|
if isinstance(v, (dict, list)):
|
|
continue
|
|
print("setting", k, "=", v)
|
|
except Exception as e:
|
|
print("settings ERR", e)
|
|
|
|
|
|
def ssh_probe():
|
|
print("\n===== VPS host probe =====")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
_, o, e = c.exec_command(
|
|
"docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' ; "
|
|
"ss -lntp | grep -E ':920|:921' | head -20 ; "
|
|
"systemctl is-active douyinweb-api.service",
|
|
timeout=30,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
api("https://dylive.nomadro.com")
|
|
api("https://dy.nomadro.com")
|
|
ssh_probe()
|