Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audiobooks with multiple folders #232

Open
StefanDorschu opened this issue Mar 7, 2023 · 4 comments
Open

Audiobooks with multiple folders #232

StefanDorschu opened this issue Mar 7, 2023 · 4 comments

Comments

@StefanDorschu
Copy link

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
Copy link
Owner

sandreas commented Mar 7, 2023

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:

  • CD 1/1 - chapter1.mp3
  • CD 1/2 - chapter2.mp3
  • CD 1/3 - chapter3.mp3
  • ...
  • CD 2/1 - chapter15.mp3
  • CD 2/2 - chapter16.mp3
  • ...

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

  • a list dump of the file structure (on linux use find -type f /path/to/audiobook, on windows use dir /s /path/to/audiobook)
  • the exact command, you are trying to run (e.g. m4b-tool merge -o output.m4b input/)

Best
Andreas

@StefanDorschu
Copy link
Author

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
Copy link
Owner

sandreas commented Mar 8, 2023

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 -):

  • /path/to/my/audiobooks/input/Fantasy/J.K. Rowling/Harry Potter/1 - Harry Potter und der Stein der Weisen

For single books, use

  • /path/to/my/audiobooks/input/Fantasy/Alexej Pehov/Dunkeljäger/

Possible issues:

  • If you copy an audio book to the input folder in the exact moment, where the script starts, the audiobook may start converting while you are still copying which results in an imcomplete book. So instead of copy you should move your content (mv "/new/audiobooks/Dunkeljäger" "/path/to/my/audiobooks/input/Fantasy/Alexej Pehov/") to prevent partial or damaged output content
  • If you are using a self hosted system with a predefined filesystem structure (like Plex, Jellyfin or AudioBookShelf), you may have to change the --batch-pattern according to that structure (e.g. https://www.audiobookshelf.org/docs#faq).

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
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants