Fix "Can't sync to MPEG frame": permissive ffmpeg fallback + stop leaking errors to clients
Confirmed from a real webapp upload (dev server log): a file Shazam
successfully identified ("Invisible" by Duran Duran, despite the local
AcoustID fingerprinter also struggling with the same file - symphonia's
demuxer logged dozens of "skipping junk"/"invalid mpeg audio header"
warnings but still recovered enough to match) then failed outright at the
ffmpeg conversion step with "Can't sync to MPEG frame", killing the whole
request with a 500 even though identification had already succeeded. This
is exactly the "messy real-world MP3s" scenario the product is meant to
handle, not an edge case worth ignoring.
- audio_processing.py: on CouldntDecodeError from pydub's default (strict)
ffmpeg invocation, retry once via a direct ffmpeg subprocess with
-err_detect ignore_err -fflags +igndts+discardcorrupt, which tells ffmpeg
to skip past bad frames instead of giving up. New AudioDecodeError is
raised only if that also fails, distinct from a bare Exception so callers
can show a clean message instead of raw ffmpeg stderr.
- music.py: both /music/upload and /music/tag now catch AudioDecodeError
specifically (422, clean user-facing message) and everything else via
logger.exception + a generic 500 message - previously upload_direct did
`raise HTTPException(500, detail=str(e))`, which is exactly the raw
ffmpeg stderr the user saw rendered directly in the webapp's error
banner, and logged nothing server-side for future diagnosis.
Verified: full 104-test suite still passes, module imports cleanly, dev
server restarted successfully.
Co-Authored-By:
Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
Showing
Please
register
or
sign in
to comment