# -*- coding: utf-8 -*- """Fix PB drift on dylive only — sync collections, NO switch/config changes.""" from __future__ import annotations import json import sys import http.cookiejar import urllib.request sys.stdout.reconfigure(encoding="utf-8", errors="replace") def call(base, path, opener=None, method="GET", body=None, timeout=300): data = None if body is None else json.dumps(body).encode() req = urllib.request.Request( f"{base}{path}", data=data, method=method, headers={"Content-Type": "application/json"} ) op = opener or urllib.request.build_opener() with op.open(req, timeout=timeout) as r: return r.status, json.loads(r.read().decode()) def login(base): cj = http.cookiejar.CookieJar() op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) call(base, "/api/auth/login", op, "POST", {"username": "hackrobot", "password": "Xiao4669805@"}) return op base = "https://dylive.nomadro.com" op = login(base) # observe switches before (must stay unchanged) before = call(base, "/api/shorts/status", op)[1] relay_before = call(base, "/api/youtube/relay/status", op)[1] print("BEFORE shorts_enabled", before.get("enabled"), "relay_enabled", relay_before.get("enabled")) print("bootstrap", call(base, "/api/pb/bootstrap", op, "POST")[1]) print("sync-rooms", call(base, "/api/pb/sync-rooms?limit=2000", op, "POST", timeout=300)[1]) print("sync-groups", call(base, "/api/pb/sync-groups?limit=2000", op, "POST", timeout=120)[1]) print("sync-sessions", call(base, "/api/pb/sync-sessions?limit=2000", op, "POST", timeout=600)[1]) pb = call(base, "/api/pb/health", op)[1] print("pb_health", { "ok": pb.get("ok"), "in_sync": pb.get("in_sync"), "max_abs_delta": pb.get("max_abs_delta"), "drift": pb.get("drift"), }) after = call(base, "/api/shorts/status", op)[1] relay_after = call(base, "/api/youtube/relay/status", op)[1] print("AFTER shorts_enabled", after.get("enabled"), "relay_enabled", relay_after.get("enabled")) assert after.get("enabled") == before.get("enabled") assert relay_after.get("enabled") == relay_before.get("enabled") h = call(base, "/api/health", op)[1] print("ops", { "yt": (h.get("youtube") or {}).get("ok"), "pb": (h.get("pocketbase") or {}).get("ok"), "s3": h.get("s3"), "ytmon": h.get("youtube_monitor"), "monitor": (h.get("monitor") or {}).get("running"), }) live = call(base, "/api/youtube/live-map", op, timeout=90)[1] print("live", live.get("live_count"), live.get("source")) # dy observe only base2 = "https://dy.nomadro.com" op2 = login(base2) h2 = call(base2, "/api/health", op2)[1] pb2 = call(base2, "/api/pb/health", op2)[1] print("\nDY observe", { "yt": (h2.get("youtube") or {}).get("ok"), "pb": (h2.get("pocketbase") or {}).get("ok"), "s3_ok": (h2.get("s3") or {}).get("ok"), "pb_in_sync": pb2.get("in_sync"), "shorts_enabled": call(base2, "/api/shorts/status", op2)[1].get("enabled"), "live": call(base2, "/api/youtube/live-map", op2, timeout=90)[1].get("live_count"), })