From 0082bec2f5a966a6edd94225ee8d7db55dc0eb49 Mon Sep 17 00:00:00 2001 From: smoochy <34371932+smoochy@users.noreply.github.com> Date: Sat, 25 Jul 2026 19:19:34 +0200 Subject: [PATCH] round1: normalize & vs and in Sonarr series title matching get_series_id() previously stripped '&' to nothing in _norm() instead of equating it with 'and', so a webhook title like 'Pam & Tommy' never matched Sonarr's stored title 'Pam and Tommy'. Add a normalized-title tier (4.5) that maps '&' -> ' and ' before comparing, applied to the primary title match (not just the alternate-titles tier), and reuse that normalization for tier 5's alternate-title comparison too. Co-Authored-By: Claude Opus 5 --- media_processor.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/media_processor.py b/media_processor.py index 61349c6..a1bfbbf 100644 --- a/media_processor.py +++ b/media_processor.py @@ -558,7 +558,7 @@ def get_series_id(series_name, thetvdb_id=None, themoviedb_id=None): if series['title'].lower() == series_name.lower(): logger.info(f"Found exact match: {series['title']}") return series['id'] - + # 4. Match without year suffixes webhook_title_clean = re.sub(r'\s*\(\d{4}\)$', '', series_name).strip() for series in series_list: @@ -566,17 +566,23 @@ def get_series_id(series_name, thetvdb_id=None, themoviedb_id=None): if sonarr_title_clean.lower() == webhook_title_clean.lower(): logger.info(f"Found match ignoring year: '{series['title']}' matches '{series_name}'") return series['id'] - - - - # 5. Alternate title match (covers localized titles, e.g. Plex "Es - Welcome to Derry") + + # 4.5 Normalized title match (treats "&" and "and" as equivalent, strips punctuation) def _norm(s): s = s.lower() + s = s.replace('&', ' and ') s = re.sub(r'[^\w\s]', '', s) s = re.sub(r'\s+', ' ', s).strip() return s - incoming_norm = _norm(series_name) + webhook_norm = _norm(series_name) + for series in series_list: + if _norm(series['title']) == webhook_norm: + logger.info(f"Found normalized title match: '{series['title']}' matches '{series_name}'") + return series['id'] + + # 5. Alternate title match (covers localized titles, e.g. Plex "Es - Welcome to Derry") + incoming_norm = webhook_norm for series in series_list: for alt in series.get('alternateTitles', []): alt_title = alt.get('title', '')