improv: phase 1 of faster scan and tracking of scans
Local Docker Build (Dev) / build-dev (push) Successful in 4s
Local Docker Build (Dev) / build-dev (push) Successful in 4s
This commit is contained in:
+40
-9
@@ -530,8 +530,8 @@ async def debug_movie_history(imdb_id: str, dependencies: dict):
|
||||
}
|
||||
|
||||
|
||||
async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = None, scan_type: str = "both", dependencies: dict = None):
|
||||
"""Manual scan endpoint"""
|
||||
async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = None, scan_type: str = "both", scan_mode: str = "smart", dependencies: dict = None):
|
||||
"""Manual scan endpoint with smart optimization modes"""
|
||||
config = dependencies["config"]
|
||||
nfo_manager = dependencies["nfo_manager"]
|
||||
tv_processor = dependencies["tv_processor"]
|
||||
@@ -540,6 +540,9 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
if scan_type not in ["both", "tv", "movies"]:
|
||||
raise HTTPException(status_code=400, detail="scan_type must be 'both', 'tv', or 'movies'")
|
||||
|
||||
if scan_mode not in ["smart", "full", "incomplete"]:
|
||||
raise HTTPException(status_code=400, detail="scan_mode must be 'smart', 'full', or 'incomplete'")
|
||||
|
||||
async def run_scan():
|
||||
from datetime import datetime, timezone
|
||||
import time
|
||||
@@ -564,7 +567,12 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
local_start = start_time
|
||||
tz_display = " (container time)"
|
||||
|
||||
print(f"🚀 MANUAL SCAN STARTED: {scan_type} scan initiated at {local_start.strftime('%Y-%m-%d %H:%M:%S')}{tz_display}")
|
||||
print(f"🚀 MANUAL SCAN STARTED: {scan_type} scan (mode: {scan_mode}) initiated at {local_start.strftime('%Y-%m-%d %H:%M:%S')}{tz_display}")
|
||||
|
||||
# Initialize counters for scan statistics
|
||||
tv_series_total = 0
|
||||
tv_series_skipped = 0
|
||||
tv_series_processed = 0
|
||||
|
||||
paths_to_scan = []
|
||||
if path:
|
||||
@@ -604,9 +612,17 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
# Check if this path itself is a series (has IMDb ID in the directory name)
|
||||
if nfo_manager.parse_imdb_from_path(scan_path):
|
||||
try:
|
||||
tv_processor.process_series(scan_path)
|
||||
# Determine force_scan based on scan mode
|
||||
force_scan = (scan_mode == "full")
|
||||
result = tv_processor.process_series(scan_path, force_scan=force_scan)
|
||||
tv_series_total += 1
|
||||
if result == "skipped":
|
||||
tv_series_skipped += 1
|
||||
elif result == "processed":
|
||||
tv_series_processed += 1
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed processing TV series {scan_path}: {e}")
|
||||
tv_series_total += 1
|
||||
else:
|
||||
# Full series processing - scan subdirectories
|
||||
import re
|
||||
@@ -618,9 +634,17 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
nfo_manager.parse_imdb_from_path(item)):
|
||||
tv_count += 1
|
||||
try:
|
||||
tv_processor.process_series(item)
|
||||
# Determine force_scan based on scan mode
|
||||
force_scan = (scan_mode == "full")
|
||||
result = tv_processor.process_series(item, force_scan=force_scan)
|
||||
tv_series_total += 1
|
||||
if result == "skipped":
|
||||
tv_series_skipped += 1
|
||||
elif result == "processed":
|
||||
tv_series_processed += 1
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed processing TV series {item}: {e}")
|
||||
tv_series_total += 1
|
||||
|
||||
# Yield control every TV series to allow other requests
|
||||
if tv_count % 1 == 0:
|
||||
@@ -668,11 +692,18 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
local_end = end_time
|
||||
tz_display = " (container time)"
|
||||
|
||||
print(f"✅ MANUAL SCAN COMPLETED: {scan_type} scan finished at {local_end.strftime('%Y-%m-%d %H:%M:%S')}{tz_display}")
|
||||
print(f"✅ MANUAL SCAN COMPLETED: {scan_type} scan (mode: {scan_mode}) finished at {local_end.strftime('%Y-%m-%d %H:%M:%S')}{tz_display}")
|
||||
print(f"⏱️ MANUAL SCAN DURATION: {duration_str} (total time: {duration.total_seconds():.1f} seconds)")
|
||||
|
||||
# Print optimization statistics for TV scans
|
||||
if scan_type in ["both", "tv"] and tv_series_total > 0:
|
||||
print(f"📊 SCAN OPTIMIZATION STATS: Total: {tv_series_total}, Processed: {tv_series_processed}, Skipped: {tv_series_skipped}")
|
||||
if tv_series_skipped > 0:
|
||||
skip_percentage = (tv_series_skipped / tv_series_total) * 100
|
||||
print(f"⚡ PERFORMANCE BOOST: {tv_series_skipped}/{tv_series_total} series skipped ({skip_percentage:.1f}% time saved!)")
|
||||
|
||||
background_tasks.add_task(run_scan)
|
||||
return {"status": "started", "message": f"Manual {scan_type} scan started"}
|
||||
return {"status": "started", "message": f"Manual {scan_type} scan started (mode: {scan_mode})"}
|
||||
|
||||
|
||||
async def scan_tv_season(background_tasks: BackgroundTasks, request: TVSeasonRequest, dependencies: dict):
|
||||
@@ -1041,8 +1072,8 @@ def register_routes(app, dependencies: dict):
|
||||
return await debug_movie_history(imdb_id, dependencies)
|
||||
|
||||
@app.post("/manual/scan")
|
||||
async def _manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = None, scan_type: str = "both"):
|
||||
return await manual_scan(background_tasks, path, scan_type, dependencies)
|
||||
async def _manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = None, scan_type: str = "both", scan_mode: str = "smart"):
|
||||
return await manual_scan(background_tasks, path, scan_type, scan_mode, dependencies)
|
||||
|
||||
@app.post("/tv/scan-season")
|
||||
async def _scan_tv_season(background_tasks: BackgroundTasks, request: TVSeasonRequest):
|
||||
|
||||
Reference in New Issue
Block a user