Show available status on landing when in Jellyfin

This commit is contained in:
2026-01-23 19:39:26 +13:00
parent b20cf0a9d2
commit cc79685eaf

View File

@@ -9,6 +9,7 @@ from datetime import datetime, timezone, timedelta
from fastapi import APIRouter, HTTPException, Depends from fastapi import APIRouter, HTTPException, Depends
from ..clients.jellyseerr import JellyseerrClient from ..clients.jellyseerr import JellyseerrClient
from ..clients.jellyfin import JellyfinClient
from ..clients.qbittorrent import QBittorrentClient from ..clients.qbittorrent import QBittorrentClient
from ..clients.radarr import RadarrClient from ..clients.radarr import RadarrClient
from ..clients.sonarr import SonarrClient from ..clients.sonarr import SonarrClient
@@ -1101,6 +1102,38 @@ async def recent_requests(
allow_remote = mode == "always_js" allow_remote = mode == "always_js"
allow_title_hydrate = mode == "prefer_cache" allow_title_hydrate = mode == "prefer_cache"
allow_artwork_hydrate = allow_remote or allow_title_hydrate allow_artwork_hydrate = allow_remote or allow_title_hydrate
jellyfin = JellyfinClient(runtime.jellyfin_base_url, runtime.jellyfin_api_key)
jellyfin_cache: Dict[str, bool] = {}
async def _jellyfin_available(
title_value: Optional[str], year_value: Optional[int], media_type_value: Optional[str]
) -> bool:
if not jellyfin.configured() or not title_value:
return False
cache_key = f"{media_type_value or ''}:{title_value.lower()}:{year_value or ''}"
cached_value = jellyfin_cache.get(cache_key)
if cached_value is not None:
return cached_value
types = ["Movie"] if media_type_value == "movie" else ["Series"]
try:
search = await jellyfin.search_items(title_value, types)
except Exception:
jellyfin_cache[cache_key] = False
return False
if isinstance(search, dict):
items = search.get("Items") or search.get("items") or []
for item in items:
if not isinstance(item, dict):
continue
name = item.get("Name") or item.get("title")
year = item.get("ProductionYear") or item.get("Year")
if name and name.strip().lower() == title_value.strip().lower():
if year_value and year and int(year) != int(year_value):
continue
jellyfin_cache[cache_key] = True
return True
jellyfin_cache[cache_key] = False
return False
results = [] results = []
for row in rows: for row in rows:
status = row.get("status") status = row.get("status")
@@ -1192,6 +1225,11 @@ async def recent_requests(
updated_at=payload.get("updated_at"), updated_at=payload.get("updated_at"),
payload_json=json.dumps(details, ensure_ascii=True), payload_json=json.dumps(details, ensure_ascii=True),
) )
status_label = _status_label(status)
if status_label == "Working on it":
is_available = await _jellyfin_available(title, year, row.get("media_type"))
if is_available:
status_label = "Available"
results.append( results.append(
{ {
"id": row.get("request_id"), "id": row.get("request_id"),
@@ -1199,7 +1237,7 @@ async def recent_requests(
"year": year, "year": year,
"type": row.get("media_type"), "type": row.get("media_type"),
"status": status, "status": status,
"statusLabel": _status_label(status), "statusLabel": status_label,
"mediaId": row.get("media_id"), "mediaId": row.get("media_id"),
"artwork": { "artwork": {
"poster_url": _artwork_url(poster_path, "w185", cache_mode), "poster_url": _artwork_url(poster_path, "w185", cache_mode),