auto-m4b

auto-m4b

Docker app from AlexRed's Repository

Overview

auto-m4b 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. See: https://github.com/seanap/beets-audible TLDR: watches a /recentlyadded folder, all multifile m4b/mp3/m4a/ogg books will be converted to a chapterized m4b and saved to an /untagged folder Github: https://github.com/seanap/auto-m4b Dockerhub: https://hub.docker.com/r/seanap/auto-m4b 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 for how to manually adjust. - Right now book folders with nested subfolders will be moved to a /fix folder for manual filename/folder fixing. It should be possible to modify the auto-m4b-tool.sh script to automatically prefix the subfoldername and move the files up a level, let me know if you know how to do this. - 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.

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

Install auto-m4b on Unraid in a few clicks.

Find auto-m4b in Community Apps on your Unraid server, review the template, and click Install. Unraid handles the Docker app or plugin setup from the published template.

Open the Apps tab on your Unraid server Search Community Apps for auto-m4b Review the template variables and paths Click Install

Requirements

Notes
===
--cpu-shares=256 by default, this will limit the container to 25% of your available CPU cycles.
Conversion speed depends on your cpu, and at 25% it can be slow. 1GB audiobook may take 30 minutes or more. Either change --cpu-shares=1024 (full cpu usage), or run it overnight.

Download Statistics

195,715
Total Downloads
7,995
This Month
8,035
Avg / Month

Total Downloads Over Time

Loading chart...

Related apps

Details

Repository
seanap/auto-m4b
Last Updated2024-07-04
First Seen2023-10-08

Runtime arguments

Network
bridge
Shell
bash
Privileged
false
Extra Params
--cpu-shares=256

Template configuration

DataPathrw
Target
/config
Default
/mnt/user/appdata/auto-m4b
Value
/mnt/user/appdata/auto-m4b
Staging FolderPathrw

Folder where operations will take place. Inside of the folder, the following structure will be used: recentlyadded, merge, untagged, delete, fix, backup. Suggested location: empty directory placed on a cache drive near your media, the subdirectories will be created automatically. Note: you may need to run chown nobody:users -R * on the folder.

Target
/temp
Save Backup Before JobVariable

[Y | N] If set to Y, will make a backup of files in the /temp/backup directory.

Target
MAKE_BACKUP
Default
N
Value
N
PUIDVariable
Default
99
Value
99
PGIDVariable
Value
100
Scan IntervalVariable

Interval to check for /temp/recentlyadded files in minutes.

Target
SLEEPTIME
Default
1m
Value
1m