[ARCH] Buryans One morning dashboard: Jellyfin/Prism status
lint / hygiene (pull_request) Failing after 23s
standard / check (pull_request) Successful in 9s
lint / hygiene (push) Failing after 18s
standard / check (push) Successful in 8s

This commit is contained in:
architect committed 2026-11-26 23:55:31 +03:00
1 parent 5889322700
commit 02298dafb7
1 file changed
+52 -8
+52 -8
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Read-only Buryans Media Alpha: Jellyfin search + minimal UI."""
import html
import http.cookiejar
import json
import urllib.error
import urllib.parse
@@ -40,19 +41,53 @@ def recent():
return out
def seerr(path):
keyfile = Path("/root/.seerr-key")
if not keyfile.exists():
return 503, {"ok": False, "error": "seerr_key_missing"}
req = urllib.request.Request(
"http://192.168.1.121:5055" + path,
headers={"X-Api-Key": keyfile.read_text().strip(), "Accept": "application/json"})
def prism_stats():
with urllib.request.urlopen("http://127.0.0.1:8095/api/prism/llm", timeout=6) as r:
return json.load(r)
def home_status():
out = {"ok": True, "alpha": "read-only", "links": {
"audit": "/", "prism": "http://192.168.1.10:9161/",
"jellyfin": "https://media.buryans.ru"}}
try:
with urllib.request.urlopen(req, timeout=8) as r:
jf("/System/Info/Public")
out["jellyfin"] = "ok"
except Exception:
out["jellyfin"] = "down"
try:
p = prism_stats()
out["prism"] = {k: p.get(k) for k in ("pending_tasks", "done_tasks", "error_tasks", "runs")}
except Exception:
out["prism"] = {"error": "unavailable"}
return out
def seerr(path):
"""Read-only Seerr requests via the local breakglass Jellyfin login."""
base = "http://192.168.1.121:5055"
cred = Path("/root/.jellyfin-breakglass")
try:
lines = cred.read_text().splitlines()
user = next(x.split("=", 1)[1] for x in lines if x.startswith("username="))
pw = next(x.split("=", 1)[1] for x in lines if x.startswith("password="))
cj = http.cookiejar.CookieJar()
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
login = urllib.request.Request(
base + "/api/v1/auth/jellyfin",
data=json.dumps({"username": user, "password": pw}).encode(),
headers={"Content-Type": "application/json"}, method="POST")
with op.open(login, timeout=8) as r:
if r.status != 200:
return 503, {"ok": False, "error": "seerr_login_%s" % r.status}
req = urllib.request.Request(base + path, headers={"Accept": "application/json"})
with op.open(req, timeout=8) as r:
return 200, json.load(r)
except urllib.error.HTTPError as e:
return (503 if e.code in (401, 403) else e.code), {
"ok": False, "error": "seerr_%s" % e.code}
except Exception as e:
return 503, {"ok": False, "error": "seerr_unavailable", "detail": str(e)[:120]}
def item(i):
@@ -181,6 +216,9 @@ class H(BaseHTTPRequestHandler):
except Exception as e:
self.out(502, {"ok": False, "error": str(e)[:300]})
return
if u.path == "/v1/home/status":
self.out(200, home_status())
return
if u.path == "/v1/media/requests":
code, body = seerr("/api/v1/request?take=20")
self.out(code, body)
@@ -232,6 +270,7 @@ button{padding:12px 16px;border-radius:8px;border:0;background:#2f81f7;color:#ff
a{color:#58a6ff}
</style></head><body>
<h1>Buryans One Alpha</h1><div class=mut id=me>read-only</div>
<div class=grid id=status style="margin:16px 0"></div>
<div class=grid style="margin:16px 0">
<a class=card href="https://media.buryans.ru" target=_blank><h3>Jellyfin</h3><div class=tag>фильмы и сериалы</div></a>
<a class=card href="https://requests.buryans.ru" target=_blank><h3>Seerr</h3><div class=tag>заявки</div></a>
@@ -248,6 +287,11 @@ a{color:#58a6ff}
const e=s=>String(s??'').replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]));
async function go(){const q=document.getElementById('q').value.trim();if(!q)return;document.getElementById('msg').textContent='поиск...';const r=await fetch('v1/media/search?q='+encodeURIComponent(q));const d=await r.json();if(!d.ok){document.getElementById('msg').textContent=d.error||'ошибка';return}document.getElementById('msg').textContent=d.items.length?'':'ничего не найдено';document.getElementById('out').innerHTML=d.items.map(x=>`<div class=card><h3>${e(x.name)}</h3><div class=tag>${e(x.type)} ${e(x.year||'')}</div><div class=mut style="margin-top:6px">${e(x.overview||'')}</div></div>`).join('')}
async function boot(){try{const m=await (await fetch('v1/me')).json();document.getElementById('me').textContent='read-only · '+(m.email||'local')}catch(e){}
try{const s=await (await fetch('v1/home/status')).json();const p=s.prism||{};document.getElementById('status').innerHTML=`
<div class=card><h3>Jellyfin</h3><div class=tag>${s.jellyfin==='ok'?'работает':'недоступен'}</div></div>
<div class=card><h3>Prism</h3><div class=tag>pending ${p.pending_tasks??'—'} · running ${p.running_tasks??'—'} · errors ${p.error_tasks??'—'}</div></div>
<div class=card><h3>Audit 360</h3><div class=tag><a href="http://192.168.1.10:9161/">открыть трекер</a></div></div>
<div class=card><h3>Режим</h3><div class=tag>read-only · без записи</div></div>`}catch(e){}
try{const r=await (await fetch('v1/media/recent')).json();const xs=r.items||[];document.getElementById('recent').innerHTML=xs.map(x=>`<div class=card><h3>${e(x.name)}</h3><div class=tag>${e(x.type)} ${e(x.year||'')}</div><div class=mut style="margin-top:6px">${e(x.overview||'')}</div></div>`).join('')}catch(e){}}
document.getElementById('q').addEventListener('keydown',e=>{if(e.key==='Enter')go()});boot();
</script></body></html>"""