dev #66

Merged
sbcrumb merged 20 commits from dev into main 2025-11-02 12:41:59 -05:00
Showing only changes of commit 614dab632a - Show all commits
+62 -2
View File
@@ -2261,6 +2261,36 @@ async def lookup_episode(imdb_id: str, season: int, episode: int, dependencies:
else:
dateadded_str = str(dateadded)
# AUTO-FIX: Update NFO file with missing dateadded element
try:
nfo_manager = dependencies.get("nfo_manager")
if nfo_manager and result.get('video_path'):
video_path = result['video_path']
print(f"DEBUG: Auto-fixing NFO for episode {imdb_id} S{season:02d}E{episode:02d} at {video_path}")
# Create NFO with dateadded element
from pathlib import Path
video_file = Path(video_path)
if video_file.exists():
# Use NFO manager to update the episode NFO file
nfo_manager.create_episode_nfo(
video_file.parent,
season,
episode,
imdb_id,
dateadded,
result.get('air_date'),
source=f"NFOGuard auto-fix via Emby lookup - {result.get('source', 'database')}"
)
print(f"SUCCESS: Auto-fixed NFO file for {imdb_id} S{season:02d}E{episode:02d}")
else:
print(f"WARNING: Video file not found for auto-fix: {video_path}")
else:
print(f"DEBUG: Auto-fix skipped - nfo_manager: {nfo_manager is not None}, video_path: {result.get('video_path', 'None')}")
except Exception as fix_error:
print(f"WARNING: Auto-fix failed for {imdb_id} S{season:02d}E{episode:02d}: {fix_error}")
# Don't fail the lookup if auto-fix fails
return {
"found": True,
"imdb_id": imdb_id,
@@ -2268,7 +2298,8 @@ async def lookup_episode(imdb_id: str, season: int, episode: int, dependencies:
"episode": episode,
"dateadded": dateadded_str,
"source": result.get('source', 'database'),
"air_date": result.get('air_date') if result.get('air_date') else None
"air_date": result.get('air_date') if result.get('air_date') else None,
"auto_fixed": True # Indicate that we attempted auto-fix
}
else:
# Not found in database
@@ -2316,12 +2347,41 @@ async def lookup_movie(imdb_id: str, dependencies: dict):
else:
dateadded_str = str(dateadded)
# AUTO-FIX: Update NFO file with missing dateadded element
try:
nfo_manager = dependencies.get("nfo_manager")
if nfo_manager and result.get('video_path'):
video_path = result['video_path']
print(f"DEBUG: Auto-fixing NFO for movie {imdb_id} at {video_path}")
# Create NFO with dateadded element
from pathlib import Path
video_file = Path(video_path)
if video_file.exists():
# Use NFO manager to update the movie NFO file
nfo_manager.create_movie_nfo(
video_file.parent,
imdb_id,
dateadded,
result.get('released'),
source=f"NFOGuard auto-fix via Emby lookup - {result.get('source', 'database')}"
)
print(f"SUCCESS: Auto-fixed NFO file for movie {imdb_id}")
else:
print(f"WARNING: Video file not found for auto-fix: {video_path}")
else:
print(f"DEBUG: Auto-fix skipped - nfo_manager: {nfo_manager is not None}, video_path: {result.get('video_path', 'None')}")
except Exception as fix_error:
print(f"WARNING: Auto-fix failed for movie {imdb_id}: {fix_error}")
# Don't fail the lookup if auto-fix fails
return {
"found": True,
"imdb_id": imdb_id,
"dateadded": dateadded_str,
"source": result.get('source', 'database'),
"released": result.get('released') if result.get('released') else None
"released": result.get('released') if result.get('released') else None,
"auto_fixed": True # Indicate that we attempted auto-fix
}
else:
# Not found in database