dev #64

Closed
sbcrumb wants to merge 6 commits from dev into main
3 changed files with 54 additions and 6 deletions
Showing only changes of commit 8dbc140b97 - Show all commits
+21 -4
View File
@@ -806,7 +806,8 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
series_path = scan_path.parent series_path = scan_path.parent
tv_processor_obj = dependencies.get("tv_processor") tv_processor_obj = dependencies.get("tv_processor")
sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None
if nfo_manager.parse_imdb_from_path_with_nfo_fallback(series_path, sonarr_client): shutdown_event = dependencies.get("shutdown_event")
if nfo_manager.parse_imdb_from_path_with_nfo_fallback(series_path, sonarr_client, shutdown_event):
print(f"INFO: Processing single season: {scan_path}") print(f"INFO: Processing single season: {scan_path}")
try: try:
tv_processor.process_season(series_path, scan_path) tv_processor.process_season(series_path, scan_path)
@@ -818,7 +819,8 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
series_path = season_path.parent series_path = season_path.parent
tv_processor_obj = dependencies.get("tv_processor") tv_processor_obj = dependencies.get("tv_processor")
sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None
if nfo_manager.parse_imdb_from_path_with_nfo_fallback(series_path, sonarr_client): shutdown_event = dependencies.get("shutdown_event")
if nfo_manager.parse_imdb_from_path_with_nfo_fallback(series_path, sonarr_client, shutdown_event):
print(f"INFO: Processing single episode: {scan_path}") print(f"INFO: Processing single episode: {scan_path}")
try: try:
tv_processor.process_episode_file(series_path, season_path, scan_path) tv_processor.process_episode_file(series_path, season_path, scan_path)
@@ -828,7 +830,8 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
# Check if this path itself is a series (has IMDb ID in directory name or NFO files) # Check if this path itself is a series (has IMDb ID in directory name or NFO files)
tv_processor_obj = dependencies.get("tv_processor") tv_processor_obj = dependencies.get("tv_processor")
sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None
if nfo_manager.parse_imdb_from_path_with_nfo_fallback(scan_path, sonarr_client): shutdown_event = dependencies.get("shutdown_event")
if nfo_manager.parse_imdb_from_path_with_nfo_fallback(scan_path, sonarr_client, shutdown_event):
try: try:
# Determine force_scan based on scan mode # Determine force_scan based on scan mode
force_scan = (scan_mode == "full") force_scan = (scan_mode == "full")
@@ -848,6 +851,12 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
# Count total series first for progress tracking # Count total series first for progress tracking
tv_series_list = [] tv_series_list = []
for item in scan_path.iterdir(): for item in scan_path.iterdir():
# Check for shutdown signal during series discovery
shutdown_event = dependencies.get("shutdown_event")
if shutdown_event and shutdown_event.is_set():
print("INFO: ⚠️ SHUTDOWN SIGNAL RECEIVED - Stopping series discovery")
return
if (item.is_dir() and if (item.is_dir() and
not item.name.lower().startswith('season') and not item.name.lower().startswith('season') and
not re.match(r'^season\s+\d+$', item.name, re.IGNORECASE)): not re.match(r'^season\s+\d+$', item.name, re.IGNORECASE)):
@@ -855,12 +864,13 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
# Check for IMDb ID (enhanced with NFO fallback) # Check for IMDb ID (enhanced with NFO fallback)
tv_processor_obj = dependencies.get("tv_processor") tv_processor_obj = dependencies.get("tv_processor")
sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None sonarr_client = tv_processor_obj.sonarr if tv_processor_obj and hasattr(tv_processor_obj, 'sonarr') else None
imdb_id = nfo_manager.parse_imdb_from_path_with_nfo_fallback(item, sonarr_client) imdb_id = nfo_manager.parse_imdb_from_path_with_nfo_fallback(item, sonarr_client, shutdown_event)
if imdb_id: if imdb_id:
tv_series_list.append(item) tv_series_list.append(item)
else: else:
# Log missing IMDb ID for TV series # Log missing IMDb ID for TV series
try: try:
db = dependencies.get("db")
db.add_missing_imdb( db.add_missing_imdb(
file_path=str(item), file_path=str(item),
media_type="tv", media_type="tv",
@@ -918,6 +928,12 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
# Count total movies first for progress tracking # Count total movies first for progress tracking
movie_list = [] movie_list = []
for item in scan_path.iterdir(): for item in scan_path.iterdir():
# Check for shutdown signal during movie discovery
shutdown_event = dependencies.get("shutdown_event")
if shutdown_event and shutdown_event.is_set():
print("INFO: ⚠️ SHUTDOWN SIGNAL RECEIVED - Stopping movie discovery")
return
if item.is_dir(): if item.is_dir():
# Check for IMDb ID # Check for IMDb ID
imdb_id = nfo_manager.find_movie_imdb_id(item) imdb_id = nfo_manager.find_movie_imdb_id(item)
@@ -926,6 +942,7 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
else: else:
# Log missing IMDb ID for movie # Log missing IMDb ID for movie
try: try:
db = dependencies.get("db")
db.add_missing_imdb( db.add_missing_imdb(
file_path=str(item), file_path=str(item),
media_type="movie", media_type="movie",
+13 -1
View File
@@ -50,7 +50,7 @@ class NFOManager:
return None return None
def parse_imdb_from_path_with_nfo_fallback(self, path: Path, sonarr_client=None) -> Optional[str]: def parse_imdb_from_path_with_nfo_fallback(self, path: Path, sonarr_client=None, shutdown_event=None) -> Optional[str]:
""" """
Enhanced IMDb detection that fallback to Sonarr ID lookup from NFO files Enhanced IMDb detection that fallback to Sonarr ID lookup from NFO files
@@ -63,6 +63,10 @@ class NFOManager:
if imdb_id: if imdb_id:
return imdb_id return imdb_id
# Check for shutdown signal before expensive operations
if shutdown_event and shutdown_event.is_set():
return None
# Fallback: Check NFO files for Sonarr series ID # Fallback: Check NFO files for Sonarr series ID
if not sonarr_client or not sonarr_client.enabled: if not sonarr_client or not sonarr_client.enabled:
return None return None
@@ -79,6 +83,10 @@ class NFOManager:
# Extract Sonarr series ID from any NFO file # Extract Sonarr series ID from any NFO file
for nfo_file in nfo_files: for nfo_file in nfo_files:
# Check for shutdown signal during NFO processing
if shutdown_event and shutdown_event.is_set():
return None
try: try:
tree = ET.parse(nfo_file) tree = ET.parse(nfo_file)
root = tree.getroot() root = tree.getroot()
@@ -87,6 +95,10 @@ class NFOManager:
for uniqueid in root.findall('.//uniqueid[@type="sonarr"]'): for uniqueid in root.findall('.//uniqueid[@type="sonarr"]'):
sonarr_id = uniqueid.text sonarr_id = uniqueid.text
if sonarr_id and sonarr_id.isdigit(): if sonarr_id and sonarr_id.isdigit():
# Check for shutdown signal before API call
if shutdown_event and shutdown_event.is_set():
return None
# Look up series in Sonarr to get IMDb ID # Look up series in Sonarr to get IMDb ID
series_data = sonarr_client.get_series_by_id(int(sonarr_id)) series_data = sonarr_client.get_series_by_id(int(sonarr_id))
if series_data: if series_data:
+19
View File
@@ -123,3 +123,22 @@ networks:
# - Webhooks remain responsive during long scans # - Webhooks remain responsive during long scans
# - Independent scaling and resource allocation # - Independent scaling and resource allocation
# - Separated concerns for maintenance and updates # - Separated concerns for maintenance and updates
# NFOGuard Core (Processing Engine)
nfoguard:
# ... other settings ...
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health/simple"]
interval: 30s
timeout: 15s # Increased from 10s
retries: 3
start_period: 60s # Increased from 40s
# NFOGuard Web Interface
nfoguard-web:
# ... other settings ...
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081/health"]
interval: 30s
timeout: 15s # Increased from 10s
retries: 3
start_period: 30s # Increased from 10s