beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.58k stars 1.8k forks source link

`badfiles` should offer to try fix broken files #5145

Open tandy-1000 opened 3 months ago

tandy-1000 commented 3 months ago

I've used this guide to fix flac files that badfiles has alerted me to.

flac -VFf --preserve-modtime -o fixed.flac corrupted.flac

mp3val also seems to have the following options:

 mp3val -f -si -nb -t corrupted.mp3

I'd be happy to work on implementing this.

Proposed solution

badfiles should provide the option to automatically try and resolve errors in FLAC and mp3 files.

Objective

It would be useful if badfiles would offer to try and fix errors for FLAC and mp3 files.

Goals

Fixable FLAC and mp3 files should (optionally) be automatically fixed.

Non-goals

This could potentially be extended to resolve errors for other formats, but is out of scope for this feature request.

Anti-goals

This should be optional and not default behaviour.

AnonTester commented 3 months ago

I was just looking at the badfiles plugin for my own config and saw this issue. I might be missing or misunderstand something, but as you can configure the exact commands in the plugin config, not sure what needs to be changed here?

badfiles:
    check_on_import: yes
    commands:
        mp3: mp3val -f -si -nb -t

tested it with manual trigger on some mp3s badfiles reported streaming errors on and the errors got fixed silently.

The badfiles plugin can run whatever command you want and isn't tied to flac or mp3val - just uses mp3val by default. If the flac command doesn't replace the file automatically, you could write a small bash wrapper script to do that for you or use a different command that could replace the file with the fixed version automatically.

tandy-1000 commented 3 months ago

That does work for mp3val, thanks for the tip. However flac requires a -o outfile argument so I can't use the custom command workaround for that.

As you suggested I've written a script:

#!/usr/bin/env bash

INPUT_FILE=${1}
OUTPUT_FILE=${INPUT_FILE}
flac -VFf --preserve-modtime -o "${OUTPUT_FILE}" "${INPUT_FILE}"
badfiles:
  check_on_import: yes
  commands:
    mp3:  mp3val -f -si -nb -t
    flac: /etc/beets/flacfixer.sh