Fix scan qui échoue

This commit is contained in:
2025-12-23 10:18:14 +01:00
parent 76d014bda2
commit c91cf634b7
3 changed files with 39 additions and 4 deletions

View File

@@ -97,7 +97,40 @@ def scan_library_task(directory: str, db: Session):
).first()
if existing:
logger.info(f"Already in database, skipping: {file_path.name}")
# Check if needs transcoding/waveform
needs_update = False
if not existing.stream_filepath or not Path(existing.stream_filepath).exists():
logger.info(f" → Needs transcoding: {file_path.name}")
needs_update = True
# Transcode to MP3 128kbps
stream_path = transcoder.transcode_to_mp3(
str(file_path),
bitrate="128k",
overwrite=False
)
if stream_path:
existing.stream_filepath = stream_path
if not existing.waveform_filepath or not Path(existing.waveform_filepath).exists():
logger.info(f" → Needs waveform: {file_path.name}")
needs_update = True
# Pre-compute waveform
waveform_dir = file_path.parent / "waveforms"
waveform_dir.mkdir(parents=True, exist_ok=True)
waveform_path = waveform_dir / f"{file_path.stem}.waveform.json"
if save_waveform_to_file(str(file_path), str(waveform_path), num_peaks=800):
existing.waveform_filepath = str(waveform_path)
if needs_update:
db.commit()
logger.info(f"✓ Updated: {file_path.name}")
else:
logger.info(f"Already complete, skipping: {file_path.name}")
scan_status["processed"] += 1
continue
@@ -211,7 +244,7 @@ async def scan_library(
)
# Use default music directory if not provided
scan_dir = directory if directory else "/music"
scan_dir = directory if directory else "/audio"
if not Path(scan_dir).exists():
raise HTTPException(

View File

@@ -86,6 +86,8 @@ class AudioTrack(Base):
return {
"id": str(self.id),
"filepath": self.filepath,
"stream_filepath": self.stream_filepath,
"waveform_filepath": self.waveform_filepath,
"filename": self.filename,
"duration_seconds": self.duration_seconds,
"file_size_bytes": self.file_size_bytes,

View File

@@ -33,8 +33,8 @@ services:
ports:
- "8001:8000"
volumes:
# Mount your audio library (read-only)
- ${AUDIO_LIBRARY_PATH:-./audio_samples}:/audio:ro
# Mount your audio library (read-write for transcoding and waveforms)
- ${AUDIO_LIBRARY_PATH:-./audio_samples}:/audio
# Mount models directory
- ./backend/models:/app/models
restart: unless-stopped