From 0e532be6f86f5256d53ff85cabc0c55673082c3e Mon Sep 17 00:00:00 2001 From: architect Date: Thu, 26 Nov 2026 23:13:58 +0300 Subject: [PATCH] [ARCH] Media Alpha read-only Jellyfin search + UI --- ops/media-alpha/README.md | 44 ++++++++++++ ops/media-alpha/media-alpha.service | 17 +++++ ops/media-alpha/media_alpha.py | 106 ++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 ops/media-alpha/README.md create mode 100644 ops/media-alpha/media-alpha.service create mode 100644 ops/media-alpha/media_alpha.py diff --git a/ops/media-alpha/README.md b/ops/media-alpha/README.md new file mode 100644 index 0000000..6fbeda6 --- /dev/null +++ b/ops/media-alpha/README.md @@ -0,0 +1,44 @@ +# Buryans Media Alpha — read-only + +Статус: local prototype, not production UI. + +## Что умеет + +- `GET /health` — Jellyfin public health; +- `GET /v1/media/search?q=` — read-only поиск по Jellyfin; +- `GET /` — минимальный UI поиска. + +## Где + +```text +127.0.0.1:9180 +/opt/media-alpha/media_alpha.py +media-alpha.service +``` + +## Auth + +Jellyfin принимает ключ только так: + +```http +Authorization: MediaBrowser Token="" +``` + +`X-Emby-Token` и `api_key` дают 401 — это не признак невалидного ключа. + +## Проверка + +```bash +curl 'http://127.0.0.1:9180/v1/media/search?q=the' +``` + +Ожидаемо: `ok=true`, список фильмов/сериалов. + +## Ограничения + +- нет SSO на самом alpha; +- нет записи/запросов; +- нет Buryans One; +- локальный доступ только с хоста. + +Следующий шаг — подключить alpha к SSO/Buryans One после проверки логина. diff --git a/ops/media-alpha/media-alpha.service b/ops/media-alpha/media-alpha.service new file mode 100644 index 0000000..3537775 --- /dev/null +++ b/ops/media-alpha/media-alpha.service @@ -0,0 +1,17 @@ +[Unit] +Description=Buryans Media Alpha (read-only Jellyfin search) +After=network-online.target + +[Service] +Type=simple +ExecStart=/usr/bin/python3 /opt/media-alpha/media_alpha.py +Restart=always +RestartSec=5 +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=full +ProtectHome=read-only +RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX + +[Install] +WantedBy=multi-user.target diff --git a/ops/media-alpha/media_alpha.py b/ops/media-alpha/media_alpha.py new file mode 100644 index 0000000..91edbe2 --- /dev/null +++ b/ops/media-alpha/media_alpha.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Read-only Buryans Media Alpha: Jellyfin search + minimal UI.""" +import html +import json +import urllib.error +import urllib.parse +import urllib.request +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +from pathlib import Path + +JF = "http://192.168.1.103:8096" +KEY = Path("/root/.jellyfin-key").read_text().strip() +HOST, PORT = "127.0.0.1", 9180 + + +def jf(path): + req = urllib.request.Request(JF + path, headers={ + "Authorization": 'MediaBrowser Token="%s"' % KEY, + "Accept": "application/json", + }) + with urllib.request.urlopen(req, timeout=10) as r: + return json.load(r) + + +def search(q): + if not q.strip(): + return [] + params = urllib.parse.urlencode({ + "searchTerm": q, "IncludeItemTypes": "Movie,Series", + "Recursive": "true", "Limit": "24", + "Fields": "ProductionYear,Overview,ImageTags,RunTimeTicks", + }) + data = jf("/Items?" + params) + out = [] + for item in data.get("Items") or []: + out.append({ + "id": item.get("Id"), + "name": item.get("Name"), + "year": item.get("ProductionYear"), + "type": item.get("Type"), + "overview": (item.get("Overview") or "")[:280], + "has_image": bool((item.get("ImageTags") or {}).get("Primary")), + }) + return out + + +class H(BaseHTTPRequestHandler): + def out(self, code, body, ctype="application/json"): + if isinstance(body, (dict, list)): + body = json.dumps(body, ensure_ascii=False) + data = body.encode() if isinstance(body, str) else body + self.send_response(code) + self.send_header("Content-Type", ctype + "; charset=utf-8") + self.send_header("Content-Length", str(len(data))) + self.end_headers() + self.wfile.write(data) + + def do_GET(self): + u = urllib.parse.urlparse(self.path) + if u.path == "/health": + try: + jf("/System/Info/Public") + self.out(200, {"ok": True, "jellyfin": True}) + except Exception as e: + self.out(503, {"ok": False, "error": str(e)[:200]}) + return + if u.path == "/v1/media/search": + q = urllib.parse.parse_qs(u.query).get("q", [""])[0] + try: + self.out(200, {"ok": True, "query": q, "items": search(q)}) + except Exception as e: + self.out(502, {"ok": False, "error": str(e)[:300]}) + return + if u.path == "/": + self.out(200, PAGE, "text/html") + return + self.out(404, {"ok": False, "error": "not found"}) + + def log_message(self, fmt, *args): + pass + + +PAGE = """ + +Buryans Media Alpha + +

Buryans Media Alpha

Read-only поиск по Jellyfin. Запросы и просмотр — в native Jellyfin.
+
+
+""" + +if __name__ == "__main__": + ThreadingHTTPServer((HOST, PORT), H).serve_forever()