A zero-dependency command-line utility for automated audiobook merging, high-quality encoding, and precision metadata tagging.
Designed to operate securely and efficiently, this script acts as a bridge for web-scraped audiobook payloads. It seamlessly digests both raw directories and .zip exports (such as those generated by LibbyRip), handling extraction, cover art downloading, chapter mapping, and containerized audio processing autonomously.
- Archive Support: Pass a
.zipfile directly; it is processed in ephemeral storage and stems are safely deleted afterward. - Smart Chapter Mapping: Converts relative JSON spine offsets into absolute
mp4chapstimestamps. - Auto-Resolution Cover Art: Dynamically downloads cover images from CDNs if a local file is missing.
- High-Quality Audio: Utilizes
libfdk_aacfor optimal voice retention and transparent compression. - Dynamic Bitrate Detection: Uses
ffprobeto match the source bitrate and prevent audio degradation. - Precision Tagging: Employs
sandreas/toneto bypass shell limits for extensive descriptions and custom narrator tags.
The utility coordinates a multi-stage pipeline to transform raw audio into a finished audiobook:
- Metadata Parsing: Extracts titles, authors, and narrators from
metadata.jsonand calculates absolute chapter timestamps based on the audio spine. - Resource Resolution: Locates or downloads the necessary cover art.
- Audio Merging: Launches a Podman container running
sandreas/m4b-toolto concatenate the source files into a single.m4bfile using the detected source bitrate. - Metadata Tagging: Launches a second Podman container running
sandreas/toneto inject high-fidelity metadata and the cover image directly into the container.
This script relies entirely on standard Python 3 libraries. However, you must have the following system-level tools installed:
- Python 3.12+
- Podman (Required for secure, rootless container processing)
- FFmpeg (Requires
ffprobein your system PATH)
brew tap alston808/m4b
brew install m4bDownload the .deb release and install via:
sudo apt install ./m4b_1.0.0_all.debgit clone [https://github.com/alston808/m4b-cli.git](https://github.com/alston808/m4b-cli.git)
cd m4b-cli
chmod +x m4b
sudo cp m4b /usr/local/bin/m4bYou can target a pre-extracted folder or pass a .zip directly. By default, the output .m4b is saved to your current working directory.
# Process an exported ZIP archive directly
m4b ~/Downloads/Audiobook_Export.zip
# Process a raw directory
m4b ~/Audiobooks/RawStems/
# Specify a custom output directory
m4b ~/Downloads/book.zip -o ~/Media/Audiobooks/- Podman Permission Errors: Ensure your user has permissions for rootless Podman. You may need to configure
subuidandsubgidif you encounter volume mounting issues. ffprobeNot Found: Ensure FFmpeg is installed andffprobeis accessible in your system's PATH.- M4B Generation Fails: Check your Podman logs. Failure is often due to corrupted source stems or insufficient temporary disk space during the merge process.
- m4b-tool by sandreas: For audio concatenation and FDK AAC encoding.
- tone by sandreas: For robust, containerized metadata injection.
- LibbyRip by PsychedelicPalimpsest: For the inspiration and structured JSON payload logic.
Alston Alika Albarado
MIT License