crra / mp3binder

🎵 concatenating, joining, binding MP3 files without re-encoding
MIT License
48 stars 5 forks source link

Doesn't handle filenames with spaces in #22

Closed pcolmer closed 2 years ago

pcolmer commented 2 years ago

I'm trying to use this tool in a way that it processes a list of files from a text file rather than allowing it to glob the directory or specifying the files individually within the command.

For example:

ls *.mp3 > list.txt
FILELIST=$(xargs -d "\n" -a list.txt ls);  mp3binder $FILELIST --lang "en-GB" --output ~/tmp.mp3

The reason for taking this approach is because some of my directories of files don't have them named correctly to respect the play order (e.g. they are missing leading zeroes on the track numbers). So I ls the directory to a file, edit the file to fix the order and then feed the list to mp3binder.

However, if the files have spaces in their names, it doesn't work. If I leave out --lang "en-GB" I get the error provided language 'C': unsupported language. After I explicitly specify --lang, the utility breaks on the first space in the first filename. I then try to work around that by getting ls to put double-quotes around the filename:

FILELIST=$(xargs -d "\n" -a list.txt ls --quoting-style=c); mp3binder $FILELIST --lang "en-GB" --output ~/tmp.mp3

but it still breaks on the first space in the first filename. It doesn't look like the commandline parser is respecting (or looking for) double-quotes.

crra commented 2 years ago

Hello @pcolmer,

thanks for bringing this up. I'll look into it.

crra commented 2 years ago

I believe xargs messes thing up. I'm using this simple bash script to see what xargs provides:

i=1;
for arg in "$@"
do
    echo "Arg - $i: $arg";
    i=$((i + 1));
done

Calling xargs the way you provided results in:

FILELIST=$(xargs -d "\n" -a list.txt ls --quoting-style=c); ./foo.sh $FILELIST
Arg - 1: "
Arg - 2: sample2.mp3"
Arg - 3: "sample
Arg - 4: 1.mp3"
Arg - 5: "sample.
Arg - 6: 4.mp3"
Arg - 7: "silence
Arg - 8: copy.mp3"

Are you interested in an --input option where you could provide the file directly?

pcolmer commented 2 years ago

Are you interested in an --input option where you could provide the file directly?

Yes, please :)

Thank you for taking the time to investigate xargs and its behaviour.

If you are able to add an --input option, that would be much appreciated!

crra commented 2 years ago

Hello @pcolmer,

please check the latest pre-release and use the option --input. There is no need to quote each line, but keep in mind that leading and tailing white spaces will be respected.

pcolmer commented 2 years ago

Hello @crra

Thank you for making this addition.

There is something about the created output file that Windows Media Player doesn't like, unfortunately. I can play it with VLC though.

Using mpck (https://github.com/Sjord/checkmate) on the built file, it reports the following:

SUMMARY: foo.mp3
    version                       MPEG v1.0
    layer                         3
    average bitrate               -21743 bps (VBR)
    samplerate                    44100 Hz
    frames                        2020051
    time                          -743:-42.-869
    unidentified                  886 b (0%)
    errors                        unidentified bytes
                                  inconsistent frame headers
                                  invalid header values
    result                        Bad

If I use the same tool on the (397) source files, they are all reported OK.

I hope that helps. Please let me know if you need me to run anything else over the files.

crra commented 2 years ago

Do you have a file to share to analyze?

crra commented 2 years ago

@pcolmer I've moved the problem with the corrupt output file to a new issue (#23) so that we can close this one (different scope).