[ARCH] Media Alpha read-only Jellyfin search + UI
This commit is contained in:
1 parent
bb54eaaeea
commit
0e532be6f8
3 files changed
+167
No files matched your search
@@ -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="<key>"
|
||||
```
|
||||
|
||||
`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 после проверки логина.
|
||||
@@ -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
|
||||
@@ -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 = """<!doctype html><html lang=ru><head><meta charset=utf-8>
|
||||
<meta name=viewport content="width=device-width,initial-scale=1">
|
||||
<title>Buryans Media Alpha</title>
|
||||
<style>
|
||||
body{background:#0d1117;color:#e6edf3;font:15px/1.5 system-ui,Arial;margin:0;padding:28px}
|
||||
h1{font-size:24px;margin:0 0 4px}.mut{color:#8b949e}
|
||||
input{width:min(600px,80%);padding:12px;border-radius:8px;border:1px solid #30363d;background:#161b22;color:#e6edf3;font-size:16px}
|
||||
button{padding:12px 16px;border-radius:8px;border:0;background:#2f81f7;color:#fff;font-size:16px;cursor:pointer}
|
||||
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:12px;margin-top:18px}
|
||||
.card{background:#161b22;border:1px solid #30363d;border-radius:10px;padding:14px}
|
||||
.card h3{margin:0 0 4px;font-size:16px}.tag{color:#8b949e;font-size:12px}
|
||||
a{color:#58a6ff}
|
||||
</style></head><body>
|
||||
<h1>Buryans Media Alpha</h1><div class=mut>Read-only поиск по Jellyfin. Запросы и просмотр — в native Jellyfin.</div>
|
||||
<div style="margin:18px 0"><input id=q placeholder="Фильм или сериал..." autofocus> <button onclick="go()">Найти</button></div>
|
||||
<div id=msg class=mut></div><div id=out class=grid></div>
|
||||
<script>
|
||||
const e=s=>String(s??'').replace(/[&<>"]/g,c=>({'&':'&','<':'<','>':'>','"':'"'}[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('')}
|
||||
document.getElementById('q').addEventListener('keydown',e=>{if(e.key==='Enter')go()});
|
||||
</script></body></html>"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
ThreadingHTTPServer((HOST, PORT), H).serve_forever()
|
||||
Reference in new issue
Block a user