A powerful, feature-rich Python script that converts MP3 audiobooks to M4B format with full metadata preservation, interactive settings, and intelligent processing.
- Settings Menu: Customizable bitrate, processing modes, and advanced options
- Discovery Preview: See exactly what will be processed before starting
- Real-time Configuration: All settings saved and persistent across sessions
- Fast Mode: Stream copy when possible (no re-encoding for compatible files)
- Quality Mode: Ensures optimal audio quality with intelligent bitrate handling
- Multi-core Support: Utilizes all CPU cores for faster processing
- Bitrate Options: 64, 96, 128, 192, 256, 320 kbps (192 kbps default)
- Processing Modes: Fast (stream copy) vs Quality (re-encode when needed)
- Chapter Naming: Auto, Sequential, or Filename-based
- Sanitization Levels: Basic or Aggressive filename cleaning
- Cover Art Quality: Original or Optimized for smaller file sizes
- Multi-structure Support: Single-folder and multi-disc audiobook structures
- Natural Sorting: Proper alphanumeric sorting (Chapter1, Chapter2, Chapter10)
- Metadata Preservation: Extracts and preserves artist, title, genre, year
- Enhanced Cover Art: Finds folder images OR extracts from MP3 metadata
- Intelligent Quality: Never upscales - only maintains or reduces bitrate
- Filename Sanitization: Removes commas, special characters for clean names
- Chapter Markers: Automatically creates navigable chapters
- Batch Processing: Process multiple audiobooks in one run
- Progress Tracking: Real-time processing updates with time estimates
- macOS (script optimized for macOS, adaptable to other systems)
- Python 3.6+ with dataclasses support
- FFmpeg & FFprobe (for audio processing)
- mutagen (Python library for MP3 metadata)
-
Install FFmpeg (if not already installed):
brew install ffmpeg
-
Install Python dependencies:
pip3 install mutagen
-
Download the script and make it executable:
chmod +x audiobook_binder.py
Launch the interactive menu system:
python3 audiobook_binder.pyInteractive Features:
- π Discovery Preview: See all audiobooks before processing
- βοΈ Settings Menu: Configure bitrate, processing mode, and advanced options
- π Progress Tracking: Real-time updates with time estimates
- ποΈ Advanced Settings: Chapter naming, cover art quality, sanitization levels
Process with current settings without menus:
python3 audiobook_binder.py --batch# Specify input directory
python3 audiobook_binder.py /path/to/audiobooks
# Custom output directory
python3 audiobook_binder.py -o /path/to/output
# Fast mode with specific bitrate
python3 audiobook_binder.py --fast --bitrate 128
# Verbose logging for troubleshooting
python3 audiobook_binder.py --verbose --batchAudioBooks/
βββ Stephen King - The Shining/
β βββ 01-Chapter1.mp3
β βββ 02-Chapter2.mp3
β βββ 03-Chapter3.mp3
β βββ cover.jpg
βββ J.K. Rowling - Harry Potter Book 1/
βββ Part1.mp3
βββ Part2.mp3
βββ folder.png
AudioBooks/
βββ Epic Fantasy Series Book 1/
β βββ Disc1/
β β βββ Track01.mp3
β β βββ Track02.mp3
β β βββ Track03.mp3
β βββ Disc2/
β β βββ Track01.mp3
β β βββ Track02.mp3
β βββ cover.jpg
βββ Science Fiction Novel/
βββ CD1/
β βββ 01-Prologue.mp3
β βββ 02-Chapter1.mp3
βββ CD2/
β βββ 01-Chapter5.mp3
β βββ 02-Epilogue.mp3
- Format:
Artist - BookTitle.m4b(commas and special characters removed) - Examples:
Stephen King - The Shining.m4bBen Greenfield - Beyond Training Mastering Endurance Health Life.m4b
- Smart Bitrate:
min(input_bitrate, max_bitrate_setting) - Fast Mode: Stream copy when input β€ target bitrate (no quality loss)
- Quality Mode: Re-encode only when necessary
π Discovery Results
==================================================
π Beyond Training- Mastering Endurance, Health & Life [2015]
π Files: 34 MP3s (545.5 MB)
π΅ Format: MP3, 89 kbps, mono
π Metadata: Ben Greenfield | Beyond Training: Mastering Endurance, Health & Life
πΌοΈ Cover Art: Embedded (500x500 JPEG)
β‘ Processing: Re-encode (89β192 kbps)
π Output: "Ben Greenfield - Beyond Training Mastering Endurance Health Life.m4b"
==================================================
π Processing Summary:
β
Total books: 1
π Total files: 34
πΎ Total size: 545.5 MB
πΌοΈ Cover art found: 1/1
β±οΈ Estimated time: 30 minutes
Proceed with processing? [Y/n]:
- Fast Mode: Stream copy when possible, minimal processing time
- Quality Mode: Ensures consistent quality, comprehensive metadata handling
- Auto: Smart detection (Disc 1 - Track 1, Chapter 01, etc.)
- Sequential: Simple Chapter 01, Chapter 02, etc.
- Filename: Uses original MP3 filenames as chapter names
- Basic: Removes illegal filesystem characters only
- Aggressive: Removes commas, semicolons, brackets, and special punctuation
- Original: Maintains original cover art resolution and quality
- Optimized: Scales to 500x500 for smaller file sizes
usage: audiobook_binder.py [-h] [-o OUTPUT] [--batch] [--bitrate {64,96,128,192,256,320}] [--fast] [--verbose] [input_dir]
AudioBook Binder - Enhanced MP3 to M4B Converter
positional arguments:
input_dir Input directory containing audiobook folders (default: current directory)
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output directory for M4B files (default: Input_dir/Output)
--batch Run in batch mode (no interactive menu)
--bitrate {64,96,128,192,256,320}
Set maximum bitrate (kbps)
--fast Use fast mode (stream copy when possible)
--verbose Enable verbose logging
Examples:
python3 audiobook_binder.py # Interactive mode
python3 audiobook_binder.py --batch # Batch mode
python3 audiobook_binder.py /path/to/books # Specify input directory
python3 audiobook_binder.py -o /path/output # Specify output directory- Fast Mode: 1.5 seconds for 15-file audiobook (stream copy)
- Quality Mode: 30 minutes for 34-file, 545MB audiobook (re-encoding)
- Automatic: Uses all available CPU cores (
-threads 0) - Configurable: Can be disabled in advanced settings
"FFmpeg is not installed or not in PATH"
brew install ffmpeg
# Restart terminal after installation"No module named 'mutagen'"
pip3 install mutagenNo audiobooks discovered
- Ensure folders contain
.mp3files - Check that you're in the parent directory containing audiobook folders
- Use
--verboseflag for detailed discovery information
- Audio:
.mp3files only - Cover Art:
.jpg,.jpeg,.png(case-insensitive) - Cover Names:
cover.*,folder.*,albumart.*,front.*
Settings are automatically saved to ~/.audiobook_binder_config.json:
{
"max_bitrate": 192,
"processing_mode": "quality",
"multi_threading": true,
"remove_commas": true,
"chapter_style": "auto",
"sanitization_level": "aggressive",
"cover_art_quality": "original",
"verbose_logging": false
}- β¨ Interactive Menu System with real-time configuration
- π Discovery Preview showing detailed analysis before processing
- β‘ Smart Processing with stream copy for compatible files
- πΌοΈ Enhanced Cover Art handling with verification
- π§Ή Advanced Sanitization removing commas and special characters
- ποΈ Configurable Settings with persistent storage
- π Progress Tracking with time estimates
- π Multi-core Support for faster processing
- π Batch Mode for automated processing
- π§ Advanced Settings for power users
This script is provided as-is for personal use. Feel free to modify and adapt as needed.
Feel free to submit issues, feature requests, or improvements! The enhanced version includes comprehensive error handling and verbose logging for easier troubleshooting.