Fix sonarr formatter crash when episodeFile.quality is a string

Sonarr can send quality as a plain string instead of the nested
{"quality": {"name": ...}} object. Guard with an isinstance check
and fall back to using the string value directly.

https://claude.ai/code/session_0188gygwJLdYhxbKvEz2jFjr
This commit is contained in:
Claude
2026-02-28 09:54:09 +00:00
parent e1de6a0794
commit 693ab9f217

View File

@@ -52,12 +52,11 @@ def format_sonarr(payload: dict) -> tuple[str, str]:
episode = ep.get("episodeNumber", 0) episode = ep.get("episodeNumber", 0)
ep_title = ep.get("title", "") ep_title = ep.get("title", "")
quality = ( quality_field = payload.get("episodeFile", {}).get("quality", {})
payload.get("episodeFile", {}) if isinstance(quality_field, dict):
.get("quality", {}) quality = quality_field.get("quality", {}).get("name", "Unknown")
.get("quality", {}) else:
.get("name", "Unknown") quality = str(quality_field) if quality_field else "Unknown"
)
header = f"\U0001f4fa **{series_title}** \u2014 S{season:02d}E{episode:02d}" header = f"\U0001f4fa **{series_title}** \u2014 S{season:02d}E{episode:02d}"
if ep_title: if ep_title: