[ARCH] Seerr session cache: requests stable 200
lint / hygiene (pull_request) Failing after 34s
standard / check (pull_request) Successful in 15s
lint / hygiene (push) Failing after 43s
standard / check (push) Successful in 14s

This commit is contained in:
architect committed 2026-11-27 10:10:15 +03:00
1 parent dc7a21ea24
commit bb2c594cbf
2 files changed
+31 -8

No files matched your search

+30 -7
View File
@@ -3,6 +3,7 @@
import html
import http.cookiejar
import json
import time
import urllib.error
import urllib.parse
import urllib.request
@@ -13,6 +14,8 @@ JF = "http://192.168.1.103:8096"
KEY = Path("/root/.jellyfin-key").read_text().strip()
HOST, PORT = "127.0.0.1", 9180
ALLOWED = {"maloyakapg@gmail.com"}
_SEERR_OP = None
_SEERR_TS = 0.0
def jf(path):
@@ -108,7 +111,15 @@ def home_status():
def seerr(path):
"""Read-only Seerr requests via the local breakglass Jellyfin login."""
global _SEERR_OP, _SEERR_TS
base = "http://192.168.1.121:5055"
if _SEERR_OP is not None and time.time() - _SEERR_TS < 1800:
try:
req = urllib.request.Request(base + path, headers={"Accept": "application/json"})
with _SEERR_OP.open(req, timeout=8) as r:
return 200, json.load(r)
except Exception:
_SEERR_OP = None
cred = Path("/root/.jellyfin-breakglass")
try:
lines = cred.read_text().splitlines()
@@ -116,13 +127,25 @@ def seerr(path):
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}
ok = False
for attempt in range(3):
login = urllib.request.Request(
base + "/api/v1/auth/jellyfin",
data=json.dumps({"username": user, "password": pw}).encode(),
headers={"Content-Type": "application/json"}, method="POST")
try:
with op.open(login, timeout=8) as r:
if r.status == 200:
ok = True
break
except urllib.error.HTTPError as e:
if e.code not in (401, 403):
raise
time.sleep(0.5)
if not ok:
return 503, {"ok": False, "error": "seerr_login_forbidden"}
_SEERR_OP = op
_SEERR_TS = time.time()
req = urllib.request.Request(base + path, headers={"Accept": "application/json"})
with op.open(req, timeout=8) as r:
return 200, json.load(r)
+1 -1
View File
@@ -28,7 +28,7 @@ class MediaPaths(unittest.TestCase):
"/v1/media/works/" + iid: 200,
"/v1/media/works/" + iid + "/availability": 200,
"/v1/media/works/" + iid + "/editions": 200,
"/v1/media/requests": 503,
"/v1/media/requests": 200,
"/v1/media/continue": 501,
"/v1/media/releases": 501,
"/v1/media/recommendations": 501,