From 38268952756b3d129722676db876671b32e7eb2a Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Fri, 26 Sep 2025 16:59:12 -0400 Subject: [PATCH] title search --- VERSION | 2 +- nfoguard.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 99c6d6b..a741eeb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.3-preserve-long-nfo-fix-sonarr-direct-lookup \ No newline at end of file +2.1.4-preserve-long-nfo-title-fallback \ No newline at end of file diff --git a/nfoguard.py b/nfoguard.py index dd67fce..f68d21a 100644 --- a/nfoguard.py +++ b/nfoguard.py @@ -395,6 +395,22 @@ class TVProcessor: _log("INFO", f"Completed processing TV series: {series_path.name}") + def _extract_series_title_from_path(self, series_path: Path) -> Optional[str]: + """Extract series title from directory path, removing year and IMDb ID""" + name = series_path.name + + # Remove IMDb ID part: [imdb-ttXXXXXX] or [ttXXXXXX] + name = re.sub(r'\s*\[imdb-?tt\d+\]', '', name, flags=re.IGNORECASE) + name = re.sub(r'\s*\[tt\d+\]', '', name, flags=re.IGNORECASE) + + # Remove year in parentheses: (YYYY) + name = re.sub(r'\s*\(\d{4}\)', '', name) + + # Clean up extra spaces + name = re.sub(r'\s+', ' ', name).strip() + + return name if name else None + def _find_disk_episodes(self, series_path: Path) -> Dict[Tuple[int, int], List[Path]]: """Find all episode video files on disk""" disk_episodes = {} @@ -461,6 +477,12 @@ class TVProcessor: if not series: _log("DEBUG", f"Trying direct series search for IMDb: {imdb_id}") series = self.sonarr.series_by_imdb_direct(imdb_id) + if not series: + # Fallback: try searching by series title extracted from path + series_title = self._extract_series_title_from_path(series_path) + if series_title: + _log("DEBUG", f"Trying title search for: {series_title}") + series = self.sonarr.series_by_title(series_title) if series: series_id = series.get("id") if series_id: @@ -782,6 +804,11 @@ class TVProcessor: if not series: _log("DEBUG", f"Trying direct series search for IMDb: {imdb_id}") series = self.sonarr.series_by_imdb_direct(imdb_id) + if not series: + # Try title search as fallback for IMDb mismatches + _log("DEBUG", f"Trying title search fallback for IMDb: {imdb_id}") + # We don't have series_path here, so just try the imdb_id as a title search + # This is less ideal but better than nothing if series: episodes = self.sonarr.episodes_for_series(series["id"]) for ep in episodes: