douyinWEB/scripts/_diag_yt_thumbs_neko_status.py
2026-09-13 22:10:49 -05:00

90 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Probe YouTube manage profile thumbs + studio status for nice street food."""
from __future__ import annotations
import json
import ssl
import sys
import urllib.request
from http.cookiejar import CookieJar
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
CTX = ssl.create_default_context()
def probe(site: str):
print(f"\n=== {site} ===", flush=True)
cj = CookieJar()
opener = urllib.request.build_opener(
urllib.request.HTTPSHandler(context=CTX),
urllib.request.HTTPCookieProcessor(cj),
)
body = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
req = urllib.request.Request(
site + "/api/auth/login",
data=body,
headers={"Content-Type": "application/json"},
method="POST",
)
with opener.open(req, timeout=30) as r:
print("login", r.status)
with opener.open(site + "/api/youtube/manage/profiles", timeout=40) as r:
data = json.loads(r.read().decode())
profiles = data.get("profiles") or {}
print("profiles", len(profiles))
for pk, p in list(profiles.items())[:12]:
thumb = (p.get("thumb_url") or "") if isinstance(p, dict) else ""
title = (p.get("title") or "") if isinstance(p, dict) else ""
status = "-"
if thumb.startswith("http"):
try:
with opener.open(thumb, timeout=12) as ir:
status = f"{ir.status}:{ir.headers.get('content-type','')[:20]}"
except Exception as e:
status = f"FAIL:{e}"
print({"pk": pk[:8], "title": title[:40], "thumb": thumb[:90], "fetch": status})
with opener.open(site + "/api/youtube/assign/groups", timeout=30) as r:
groups = json.loads(r.read().decode()).get("groups") or []
for g in groups:
if "nice" in str(g.get("name") or "").lower() or "street" in str(g.get("name") or "").lower():
print("group", {k: g.get(k) for k in (
"id","name","neko_instance_id","neko_enabled","ops_neko_prefer","ops_neko_slot","channel_pk"
)})
gid = g.get("id")
break
else:
gid = groups[0]["id"] if groups else ""
print("first_group", groups[0].get("name") if groups else None)
# studio status if any
try:
with opener.open(site + "/api/youtube/studio/status", timeout=20) as r:
st = json.loads(r.read().decode())
print("studio_keys", list(st.keys())[:20] if isinstance(st, dict) else type(st))
items = st.get("items") or st.get("groups") or st.get("status") or st
if isinstance(items, dict):
for k, v in list(items.items())[:5]:
if isinstance(v, dict):
print("studio", k[:8], {kk: v.get(kk) for kk in ("on_air","live_page_open","viewer_count","neko_kind","ui_source")})
elif isinstance(items, list):
for v in items[:5]:
print("studio", {kk: v.get(kk) for kk in ("group_id","on_air","live_page_open","viewer_count")})
except Exception as e:
print("studio_err", e)
# neko status for instance 10
try:
with opener.open(site + "/api/youtube/neko/10/status", timeout=20) as r:
print("neko10", json.loads(r.read().decode()))
except Exception as e:
print("neko10_err", e)
for s in ("https://dylive.nomadro.com", "https://dy.nomadro.live"):
try:
probe(s)
except Exception as e:
print("SITE_ERR", s, e)
print("ALL_DONE", flush=True)