Skip to content

Docker container that watches a folder for multi-file mp3 books and converts them to a chapterized m4b.

Notifications You must be signed in to change notification settings

seanap/auto-m4b

Repository files navigation

Auto-M4B

Join the chat at https://gitter.im/Audiobook-Server/auto-m4b

This container is mostly based on the powerful m4b-tool made by sandreas
This repo is my fork of the fantastic docker-m4b-tool created by 9Mad-Max5.

This is a docker container that will watch a folder for new books, auto convert mp3 books to chapterized m4b, and move all m4b books to a specific output folder, this output folder is where the beets.io audible plugin will look for audiobooks and use the audible api to perfectly tag and organize your books.

Intended Use

This is meant to be an automated step between aquisition and tagging.

  • Install via docker-compose
  • Save new audiobooks to a /recentlyadded folder.
  • All multifile m4b/mp3/m4a/ogg books will be converted to a chapterized m4b and saved to an /untagged folder
  • This script will watch /temp/recentlyadded and automatically move mp3 books to /temp/merge, then automatically put all m4b's in the output folder /temp/untagged. It also makes a backup incase something goes wrong (can be disabled if desired).

Use the beets.io audible plugin to finish the tagging and sorting.

Known Limitations

  • The chapters are based on the mp3 tracks. A single mp3 file will become a single m4b with 1 chapter, also if the mp3 filenames are garbarge then your m4b chapternames will be terrible as well. See section on Chapters below for how to manually adjust.
  • The conversion process actually strips some tags and covers from the files, which is why you need to use a tagger (mp3tag or beets.io) before adding to Plex.

Need ARM Support?

Change the image to spencermksmith/auto-m4b

Using torrents and need to preserve seeding?

In the settings of your client add this line to Run external program on torrent completion, it will copy all finished torrent files to your "recentlyadded" folder:

  • cp -r "%F" "path/to/temp/recentlyadded"

How to use

This docker assumes the following folder structure:

temp
│
└───recentlyadded # Input folder Add new books here
│     │     book1.m4b
│     |     book2.mp3
|     └─────book3
│           │   01-book3.mp3
│           │   ... 
└───merge # folder the script uses to combine mp3's
│     └─────book2
│           │   01-book2.mp3
│           │   ...
└───untagged # Output folder where all m4b's wait to be tagged
│     └─────book4
│           │   book4.m4b
└───delete # needed by the script
|
└───fix # Manually fix books
|
└───backup # Backups incase anything goes wrong
      └─────book2
            │   01-book2.mp3
            │   ... 

Installation

  1. Create a temp folder and keep the location in mind for Step 6
  2. Install docker https://docs.docker.com/engine/install/ubuntu/
  3. Manage docker as non-root https://docs.docker.com/engine/install/linux-postinstall/
  4. Install docker-compose https://docs.docker.com/compose/install/
  5. Create the compose file:
    nano docker-compose.yml
  6. Paste the yaml code below into the compose file, and change the volume mount locations
  7. Put a test mp3 in the /temp/recentlyadded directory.
  8. Start the docker (It should convert the mp3 and leave it in your /temp/untagged directory. It runs automatically every 5 min)
    docker-compose up -d

Example docker-compose.yml

  • Replace the /path/to/... with your actual folder locations, but leave the : and everything after:
  • Replace the PUID and PGID with your user ( ? )

docker-compose.yml

version: '3.7'
services:
  auto-m4b:
    image: seanap/auto-m4b
    container_name: auto-m4b
    volumes:
      - /path/to/config:/config
      - /path/to/temp:/temp
    environment:
      - PUID=1000
      - PGID=1000
      - CPU_CORES=2
      - SLEEPTIME=1m
      - MAKE_BACKUP=Y

To Manually Set Chapters:

  1. Put a folder with mp3's in the /temp/recentlyadded and let the script process the book like normal
  2. In the output folder ( /temp/untagged ) there will be a book folder that includes the recently converted *.m4b and a *.chapters.txt file.
  3. Open the chapters file and edit/add/rename, then save
  4. Move the book folder (which contains the m4b and chapters.txt files) to /temp/merge
  5. When the script runs it will re-chapterize the m4b and move it back to /temp/untagged

Advanced Options

Edit the script that is run

You shouldn't need to change any options, but if you want to you will need to exec into the docker container. By default only vim text editor is installed, you will need to do a apt-get update && apt-get install nano if you want to use nano to edit the scipt.

  • docker exec -it auto-m4b sh -c 'vi auto-m4b-tool.sh'

CPU Cores

The script will automatically use all CPU cores available, to change the amount of cpu cores for the converting change the --jobs flag in the m4b-tool command, but do not set it higher than the amount of cores available.

Backup Folder

For those copying files from another source into the recentlyadded folder, it might not make sense to waste time copying to the backup folder (because they were already copied from somewhere else). Backing up is enabled by default. To disable this copy operation, change this line in your compose file: - MAKE_BACKUP=N.

More Reading

More m4b-tool options https://github.com/sandreas/m4b-tool#reference

About

Docker container that watches a folder for multi-file mp3 books and converts them to a chapterized m4b.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published