From f0b1fc905250cc693faa1a8906cfd01a06ee824f Mon Sep 17 00:00:00 2001 From: pax Date: Thu, 9 Apr 2026 17:16:12 -0500 Subject: [PATCH] config: render_filename_template now matches the API client key casing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The danbooru and e621 API clients store tag_categories with Capitalized keys ("Artist", "Character", "Copyright", "General", "Meta", "Species") — that's the convention info_panel and preview_pane already iterate against. render_filename_template was looking up lowercase keys, so every category token rendered empty even on Danbooru posts where the data was right there. Templates like "%id%_%character%" silently collapsed back to "{id}.{ext}". Fix: look up the Capitalized form, with a fallback chain (exact -> .lower() -> .capitalize()) so future drift between API clients in either direction won't silently break templates again. Verified against a real Danbooru save in the user's library: post 11122211 with tag_categories containing Artist=["yun_ze"], Character=["mon3tr_(arknights)"], etc. now renders "%id%_%character%" -> "11122211_mon3tr_(arknights).jpg" instead of "11122211.jpg". --- booru_viewer/core/config.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/booru_viewer/core/config.py b/booru_viewer/core/config.py index 897a797..430e4e4 100644 --- a/booru_viewer/core/config.py +++ b/booru_viewer/core/config.py @@ -190,7 +190,12 @@ def render_filename_template(template: str, post: "Post", ext: str) -> str: cats = post.tag_categories or {} def _join_cat(name: str) -> str: - items = cats.get(name) or [] + # API clients (danbooru.py, e621.py) store categories with + # Capitalized keys ("Artist", "Character", ...) — that's the + # convention info_panel/preview_pane already iterate against. + # Accept either casing here so future drift in either direction + # doesn't silently break templates. + items = cats.get(name) or cats.get(name.lower()) or cats.get(name.capitalize()) or [] return "_".join(items) # %md5% — most boorus name files by md5 in the URL path @@ -213,12 +218,12 @@ def render_filename_template(template: str, post: "Post", ext: str) -> str: "%ext%": ext.lstrip("."), "%rating%": post.rating or "", "%score%": str(post.score), - "%artist%": _join_cat("artist"), - "%character%": _join_cat("character"), - "%copyright%": _join_cat("copyright"), - "%general%": _join_cat("general"), - "%meta%": _join_cat("meta"), - "%species%": _join_cat("species"), + "%artist%": _join_cat("Artist"), + "%character%": _join_cat("Character"), + "%copyright%": _join_cat("Copyright"), + "%general%": _join_cat("General"), + "%meta%": _join_cat("Meta"), + "%species%": _join_cat("Species"), } rendered = template