Update scan logic

This commit is contained in:
2025-10-31 22:03:02 +11:00
parent c7fbfcd732
commit 6f9596be4a
+15 -1
View File
@@ -257,7 +257,7 @@ async def scan_directory(db: AsyncSession, directory: str) -> Dict[str, int]:
return {"added": 0, "updated": 0, "errors": 0}
supported_formats = {'.mp3', '.flac', '.m4a', '.mp4', '.wav', '.ogg', '.wma', '.aac'}
stats = {"added": 0, "updated": 0, "errors": 0}
stats = {"added": 0, "updated": 0, "errors": 0, "skipped": 0}
logger.info(f"Scanning directory: {directory}")
@@ -271,8 +271,22 @@ async def scan_directory(db: AsyncSession, directory: str) -> Dict[str, int]:
scan_status["progress"] += 1
try:
# Check file size first (skip if < 1 MB)
file_size = os.path.getsize(file_path)
if file_size < 1024 * 1024: # 1 MB in bytes
logger.debug(f"Skipping {file}: file size too small ({file_size} bytes)")
stats["skipped"] += 1
continue
metadata = extract_metadata(file_path)
if metadata:
# Check duration (skip if < 90 seconds)
duration = metadata.get("duration")
if duration and duration < 90:
logger.debug(f"Skipping {file}: duration too short ({duration}s)")
stats["skipped"] += 1
continue
result = await create_or_update_music(db, file_path, metadata, directory)
if result == "added":
stats["added"] += 1