Move search results into poster grid

This commit is contained in:
Dymas
2026-06-02 11:06:13 +02:00
parent d075aa11f9
commit 94740ebb76
7 changed files with 232 additions and 29 deletions
+34
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import base64
import hashlib
import gzip
import json
import mimetypes
@@ -146,6 +147,12 @@ def cover_route(show_id):
return f"/api/watchlist/thumb/{quote(str(show_id).strip(), safe='')}"
def search_thumbnail_cache_key(title):
normalized = normalize_title_key(title) or str(title or "").strip().casefold()
digest = hashlib.sha1(normalized.encode("utf-8")).hexdigest()[:12]
return f"search-{digest}"
def anime_source_url(show_id, title):
normalized_show_id = str(show_id or "").strip()
if not normalized_show_id:
@@ -774,6 +781,32 @@ def fetch_anidb_cover_by_aid(aid, fallback_title=""):
}
def resolve_search_thumbnail(title):
clean_title = str(title or "").strip()
if not clean_title:
raise ValueError("Missing title for thumbnail lookup")
cache_key = search_thumbnail_cache_key(clean_title)
THUMBNAIL_ROOT.mkdir(parents=True, exist_ok=True)
for existing in THUMBNAIL_ROOT.glob(f"{cache_key}.*"):
if existing.is_file():
return existing
cover = None
last_error = None
for resolver in (fetch_animeschedule_cover, fetch_anidb_cover):
try:
cover = resolver(clean_title)
break
except Exception as exc:
last_error = exc
if not cover:
raise RuntimeError("Could not find a thumbnail for this search result") from last_error
cached_name = cache_thumbnail_image(cache_key, cover["url"])
path = thumbnail_file_path(cached_name)
if not path or not path.exists():
raise RuntimeError("Could not cache the search thumbnail")
return path
def cache_thumbnail_image(show_id, image_url):
THUMBNAIL_ROOT.mkdir(parents=True, exist_ok=True)
debug_log("thumbnail.download.request", show_id=show_id, image_url=image_url)
@@ -2816,6 +2849,7 @@ Handler = build_handler_class(
runtime_state=runtime_state,
save_runtime_config=save_runtime_config,
search_anime=search_anime,
resolve_search_thumbnail=resolve_search_thumbnail,
test_discord_webhook_config=test_discord_webhook_config,
thumbnail_file_path=thumbnail_file_path,
update_all_watchlist_statuses=update_all_watchlist_statuses,