From 581087748954cf3711b084f13f4b80194177caf8 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Fri, 26 Sep 2025 08:35:54 -0400 Subject: [PATCH] feat: Complete elimination of short NFO names - always match video filenames - Added logic to actively delete existing S01E01.nfo short-name files - Modified fallback creation to always match video file names - Added find_video_file_for_episode() to locate matching video files - NFO files will now ALWAYS have the same name as their video files - No more S01E01.nfo format ever created, addressing Emby compatibility issues This ensures complete consistency between NFO and video file naming, which should resolve Emby metadata reading issues. --- VERSION | 2 +- core/nfo_manager.py | 44 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 77fee73..d615fd0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.9.3 +1.9.4 diff --git a/core/nfo_manager.py b/core/nfo_manager.py index b801406..33e222c 100644 --- a/core/nfo_manager.py +++ b/core/nfo_manager.py @@ -650,11 +650,29 @@ class NFOManager: else: print(f"⚠️ Failed to update existing NFO, falling back to standard creation") - # Fallback: Create standard S01E01.nfo format (for new episodes without existing NFOs) - episode_filename = f"S{season_num:02d}E{episode_num:02d}.nfo" - nfo_path = season_dir / episode_filename + # Check for and remove old short-name NFO files (S01E01.nfo format) + short_nfo_path = season_dir / f"S{season_num:02d}E{episode_num:02d}.nfo" + if short_nfo_path.exists(): + print(f"🗑️ Removing old short-name NFO: {short_nfo_path.name}") + try: + short_nfo_path.unlink() + print(f"✅ Deleted short-name NFO file: {short_nfo_path.name}") + except Exception as e: + print(f"⚠️ Warning: Could not delete short-name NFO {short_nfo_path.name}: {e}") - # Check if standard format NFO exists + # Fallback: Create NFO file matching video file name (no more short S01E01.nfo names) + video_file = self.find_video_file_for_episode(season_dir, season_num, episode_num) + if video_file: + # Create NFO with same name as video file + nfo_path = video_file.with_suffix('.nfo') + print(f"🎬 Creating new NFO matching video file: {nfo_path.name}") + else: + # Last resort: create with season/episode pattern (but this should rarely happen) + episode_filename = f"S{season_num:02d}E{episode_num:02d}.nfo" + nfo_path = season_dir / episode_filename + print(f"⚠️ No video file found, creating basic NFO: {episode_filename}") + + # Check if NFO already exists source_nfo_path = nfo_path if nfo_path.exists() else None if source_nfo_path: @@ -1034,4 +1052,22 @@ class NFOManager: continue return None + + def find_video_file_for_episode(self, season_dir: Path, season_num: int, episode_num: int) -> Optional[Path]: + """Find the video file for a specific episode to match NFO naming""" + if not season_dir.exists(): + return None + + # Find video files for this episode (check common patterns) + season_episode_pattern = f"S{season_num:02d}E{episode_num:02d}" + + # Look for video files with season/episode pattern + video_extensions = ['.mkv', '.mp4', '.avi', '.m4v'] + for ext in video_extensions: + video_files = list(season_dir.glob(f"*{season_episode_pattern}*{ext}")) + if video_files: + # Return the first matching video file + return video_files[0] + + return None