From a555fb6b515a05316f3aae71e9fff3488512fa50 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Sun, 20 Sep 2026 14:32:03 -0700 Subject: [PATCH] Check near-year candidates before the unique exact-title fallback in best_match --- plex-library-tool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plex-library-tool.py b/plex-library-tool.py index 38be98e..2d1d75a 100755 --- a/plex-library-tool.py +++ b/plex-library-tool.py @@ -983,10 +983,6 @@ def best_match(media_type, results, year, query=None): if not query_norm: return None - exact_matches = [r for r in results if is_exact_title(r)] - if len(exact_matches) == 1: - return exact_matches[0] - def near_title_similarity(r): return difflib.SequenceMatcher( None, query_norm, clean_and_squeeze(result_title(media_type, r) or "").lower() @@ -1001,6 +997,11 @@ def best_match(media_type, results, year, query=None): threshold = YEAR_MATCH_MIN_SIMILARITY if len(near_year_matches) == 1 else NEAR_YEAR_MATCH_MIN_SIMILARITY if near_title_similarity(best) >= threshold: return best + + exact_matches = [r for r in results if is_exact_title(r)] + if len(exact_matches) == 1: + return exact_matches[0] + return None if not query_norm: return year_matches[0]