sandreas / m4b-tool

m4b-tool is a command line utility to merge, split and chapterize audiobook files such as mp3, ogg, flac, m4a or m4b
MIT License
1.12k stars 79 forks source link

Audiobooks with multiple folders #232

Open StefanDorschu opened 1 year ago

StefanDorschu commented 1 year ago

I would like to merge an audiobook that consists of multiple folder (CD1, CD2 etc.).

I can not copy the files to one folder, because then the chapters are in the wrong order as the tracks are numbered from 1 to... in each folder.

When i try to merge the parent folder this audiobook is moved to the "fix"-folder.

Best regards,

Stefan

sandreas commented 1 year ago

I would like to merge an audiobook that consists of multiple folder (CD1, CD2 etc.).

This should work. m4b-tool performs a natural sort of files before merging anything, which means that the order would be:

If it does not work like you would expect, I need:

Best Andreas

StefanDorschu commented 1 year ago

Hi Andreas,

i found my problem :) I thought i would be using your files, instead i'm running the "docker"-fork of seanap.

I think the way it is automating the task is causing the problem.

The code which is run is

https://github.com/seanap/auto-m4b/blob/main/auto-m4b-tool.sh

In line 71 the way is handling nested folders is the problem. But i think my skills are too limited here to fix ist :(

Best regards and thank you for all of your help,

Stefan

sandreas commented 1 year ago

instead i'm running the "docker"-fork of seanap.

While I appreciate the fact, that other people are using my tools to create scripts like that, I think that the specific script is overcomplicating everything and causing a lot of unnecessary load on the file system... instead of using the --batch-pattern feature, it tries to move files around and does backups of the original folder where not necessary.

I personally think that a tool like inotifywait would have been the right choice to implement this (instead of a while loop). See https://www.baeldung.com/linux/monitor-changes-directory-tree for details.

But i think my skills are too limited here to fix ist :(

Are you running linux? If so you could do the following very simple approach:

#!/bin/sh
CPU_CORES="2"
INPUT_PATH="/path/to/my/audiobooks/input/"
OUTPUT_PATH="/path/to/my/audiobooks/output/"

while [ true ]; do
    docker run -it -rm -u $(id -u):$(id -g) -v "$INPUT_PATH":/mnt -v "$OUTPUT_PATH":/output sandreas/m4b-tool:latest merge --jobs=$CPU_CORES --no-cache -v --batch-pattern="/mnt/%g/%a/%s/%p - %n/" --batch-pattern="/mnt/%g/%a/%n/" "/mnt/" --output-file="/output/" --max-chapter-length=300,900 --adjust-for-ipod --audio-channels=1 --audio-bitrate=64k --audio-samplerate=22050 --audio-codec=libfdk_aac --audio-profile=aac_he --equate=name,album --ignore-source-tags --prepend-series-to-longdesc --silence-min-length=1000 --chapter-algo=grouping --skip-cover-if-exists
    # wait 5 Minutes to prevent to much filesystem load
    sleep 300
done

That's it... Now you can put your files into an organized structure like this:

For series add the part number (1 -):

For single books, use

Possible issues:

I'm currently working on reorganising my personal filesystem structure to support AudioBookShelf. As soon as it's done, I plan to update the documentation with a guide supporting it. Another feature I'm planning for tone is to watch a filesystem structure and run a script / command (something like tone watch /path/to/audiobooks --run="m4b-tool merge /path/to/audiobooks/ -o /output/ ..." --no-changes-for="300". That would make auto-m4b-tool obsolete, but I've not even started to implement this feature.

StefanDorschu commented 1 year ago

Thank you again. Currently i'm trying to setup the docker container (on a synology nas). I have only used docker compose yet, so still need some time/help to get it running :)