From c91cf634b7479a8b2f39be194d53592bdd998f06 Mon Sep 17 00:00:00 2001 From: Benoit Date: Tue, 23 Dec 2025 10:18:14 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20scan=20qui=20=C3=A9choue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/api/routes/library.py | 37 +++++++++++++++++++++++++++++-- backend/src/models/schema.py | 2 ++ docker-compose.yml | 4 ++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/backend/src/api/routes/library.py b/backend/src/api/routes/library.py index e98c86b..f5e020c 100644 --- a/backend/src/api/routes/library.py +++ b/backend/src/api/routes/library.py @@ -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( diff --git a/backend/src/models/schema.py b/backend/src/models/schema.py index cde3940..c01a72d 100644 --- a/backend/src/models/schema.py +++ b/backend/src/models/schema.py @@ -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, diff --git a/docker-compose.yml b/docker-compose.yml index 3643a6f..8099b91 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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