Fix Sonarr series-title matching for ampersand vs "and" (e.g. "Pam & Tommy") - #86
Open
smoochy wants to merge 1 commit into
Open
Fix Sonarr series-title matching for ampersand vs "and" (e.g. "Pam & Tommy")#86smoochy wants to merge 1 commit into
smoochy wants to merge 1 commit into
Conversation
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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
get_series_id()inmedia_processor.pyfailed to match "Pam & Tommy" against Sonarr's stored title "Pam and Tommy" (tvdbId 400690, Sonarr series id 181), even though the series exists, is monitored, and has episodes.Root cause: the title-normalization helper
_norm()stripped&entirely (viare.sub(r'[^\w\s]', '', s)) instead of equating it withand. So_norm("Pam & Tommy")→"pam tommy"while_norm("Pam and Tommy")→"pam and tommy"— not equal. Every matching tier failed:&vsand)_norm()doesn't equate&/and"pam & tommy"is not a substring of"pam and tommy"or vice versa, so even the debug fallback logged "No close matches"Why the TVDB-ID match (tier 1) didn't save this case
Sonarr does have the correct tvdbId (400690), and Plex's own metadata is correctly linked to the same TVDB entry — confirmed directly via the Plex API:
(from
GET /library/metadata/935on the live Plex server, item "Pam & Tommy")However, Tautulli's
{thetvdb_id}webhook template variable did not populate for this item across multiple playback events over several hours, despite Plex having correct metadata and the Tautulli notification agent's JSON body being configured correctly (verified against the user's actual live notification agent config):{ "plex_title": "{show_name}", "plex_movie_title": "{title}", "plex_season_num": "{season_num}", "plex_ep_num": "{episode_num}", "thetvdb_id": "{thetvdb_id}", "themoviedb_id": "{themoviedb_id}", "media_type": "{media_type}", "notification_type": "playback start" }This points to a Tautulli-side limitation/bug in resolving
{thetvdb_id}for this item (out of scope for this repo), which means the title-matching fallback is not a rare edge case here — it's the path actually doing the work when Tautulli's ID fields come through empty.Log evidence
episeerr (
missing_logger, repeated across multiple playback events, 19:06–21:08):Sonarr (
GET /api/v3/series/lookup?term=Pam%20%26%20Tommy) confirms the series is present under a different title string:{ "title": "Pam and Tommy", "tvdbId": 400690, "tmdbId": 114925, "id": 181, "monitored": true, "statistics": {"seasonCount": 1, "episodeCount": 8} }Tautulli (docker logs, same playback sessions) shows the correct show name reaching Tautulli itself, confirming the data loss happens between Tautulli and its outbound webhook, not in Plex→Tautulli:
Plex (
GET /library/metadata/935) confirms the show has correct TVDB linkage on the Plex side:Fix
Added a normalized-title comparison tier to
get_series_id()that maps&→andbefore stripping punctuation, checked as its own tier right after the year-suffix match (so it's tried before falling back to alternate titles), and reused the same normalization helper for the existing alternate-titles tier instead of duplicating logic:Verification
Built the fixed image, deployed it to a live homelab instance running actual Sonarr/Tautulli integrations, and sent a Tautulli-style webhook POST with
plex_title: "Pam & Tommy"(nothetvdb_id/themoviedb_id, matching the real-world failure case) against the live redeployed container. Confirmed:Found normalized title match: 'Pam and Tommy' matches 'Pam & Tommy'Series not found in Sonarr: 'Pam & Tommy'. No close matches.🤖 Generated with Claude Code