PostRipM4B is a comprehensive audiobook converter designed specifically for processing output from LibbyRip. It converts MP3 files with embedded metadata into properly formatted M4B audiobook files with chapters, cover art, and accurate metadata.
- Dual Interface: Both command-line (CLI) and graphical (GUI) interfaces
- Chapter Support: Multiple chapter formats (Libby, ffmetadata, m4b-tool, Audacity)
- Smart Processing: Auto-detects optimal parallel workers and audio settings
- Cover Art: Automatic cover image detection and embedding
- Metadata Preservation: Maintains author, title, narrator, and other book information
- Chapter Editor: Built-in GUI editor for fine-tuning chapter timings and titles
- Cross-Platform: Works on Windows, macOS, and Linux
- iTunes Sort Name: Writes the Sort Name tag for M4B files
- "When done" actions: Optionally quit, sleep, or shut down the computer after conversions finish (Batch tab or
--when-done)
- Rip audiobook using LibbyRip
- Extract the ZIP file that LibbyRip produces
- Run PostRipM4B on the extracted folder:
- GUI Mode:
python PostRipM4b.py --gui <path-to-extracted-folder> - CLI Mode:
python PostRipM4b.py <path-to-extracted-folder>
- GUI Mode:
- Python 3.8 or higher
- FFmpeg installed and in your system PATH
- mutagen (for writing iTunes Sort Name)
-
Clone the repository:
git clone https://github.com/yourusername/PostRipM4B.git cd PostRipM4B -
Install required packages:
pip install -r requirements.txt -
Ensure FFmpeg is installed:
- Windows: Download from ffmpeg.org
- macOS:
brew install ffmpeg - Linux:
sudo apt install ffmpeg(Ubuntu/Debian) or use your package manager
PostRipM4B requires Python 3.8+ and PyQt5. We recommend using a virtual environment to manage dependencies.
-
Create the virtual environment:
python3 -m venv .venv -
Activate the virtual environment:
-
Linux/macOS:
source .venv/bin/activate -
Windows (Command Prompt):
.venv\Scripts\activate -
Windows (PowerShell):
.venv\Scripts\Activate.ps1
-
-
Install required packages:
pip install -r requirements.txt -
Verify installation:
python PostRipM4b.py --helpYou should see the help message with all available options.
For easier execution on Linux/macOS, a convenience script is provided:
-
Make the script executable:
chmod +x PostRipM4B.sh -
Run the converter:
./PostRipM4B.sh --guiOr with command-line arguments:
./PostRipM4B.sh /path/to/audiobook --bitrate 128k --title "My Book"
The script automatically:
- Checks for the virtual environment
- Activates it if found
- Runs the converter with proper Python environment
-
Always activate the virtual environment before running
pip installor the converter directly -
Your shell prompt will show
(.venv)when the environment is active -
To deactivate the environment when done, simply run:
deactivate -
Or close the terminal - the environment is only active in that session
If you encounter "ModuleNotFoundError" for PyQt5:
-
Ensure the virtual environment is activated (you should see
(.venv)in your prompt) -
Reinstall requirements:
pip install --upgrade -r requirements.txt -
Check Python version in venv:
python --version -
Verify PyQt5 is installed:
pip list | grep PyQt5
python PostRipM4b.py --gui /path/to/extracted/audiobook
The GUI provides:
- Visual configuration of all settings
- Chapter preview and editing
- Real-time progress tracking
- One-click conversion
python PostRipM4b.py /path/to/extracted/audiobook
input_dir: Directory containing MP3 files (default: current directory)-o, --output-dir: Output directory for M4B file (default: <input_dir>/m4b/)-n, --output-name: Output filename (without extension, defaults to book title)--overwrite: Overwrite existing output file
-b, --bitrate: Audio bitrate (e.g., 64k, 128k, 256k, defaults to auto-detect)--sample-rate: Sample rate in Hz (e.g., 44100, 48000, defaults to source)--channels: Audio channels (1=mono, 2=stereo, defaults to source)
--metadata: Path to metadata file (backward compatibility, assumes Libby format)--libby-chapters: Path to Libby metadata.json file--ffmetadata-chapters: Path to ffmetadata.txt file--m4btool-chapters: Path to m4b-tool/tone chapters.txt file--audacity-chapters: Path to Audacity label file
--cover: Path to cover image (default: auto-detect)--no-cover: Don't embed cover image even if available
Values from the metadata/chapter file take precedence. Command-line values (and GUI entries) are used only when the metadata file does not provide a value for that field.
--title: Book title (falls back to the input directory name when neither the metadata file nor--titleprovides one)--author: Author--narrator: Narrator (written to the M4B when present)--year: Set release year (empty/omitted when not provided, from metadata file, or entered in the GUI)--genre: Set genre--comment: Add comment/description--track-num: Track number (default: 1)--sort-name: iTunes sort name (default: value of--titleif provided, otherwise from metadata file)--media-type: iTunes media type (default: 2)--album: Album tag (default: value of--titleif provided, otherwise from metadata file)
Title-based defaults: The title is resolved in this order: metadata file → --title → input directory name. When a title is resolved and --album/sort_name are not provided by the metadata file, both album and sort_name are automatically populated with the title value. Explicit values from the metadata file take precedence. This same behavior applies in GUI mode — loading metadata will populate Sort Name and Album from the title if those fields are not already set in the source metadata.
-w, --workers: Number of parallel workers (default: auto-detect)--no-optimize: Skip optimization step--keep-temp: Keep temporary files after completion--temp-dir: Directory for temporary files (default: tracks the input dir as <input_dir>/tmp/)--max-retries: Maximum retries for failed conversions (default: 3)
-q, --quiet: Minimal output (errors only)-v, --verbose: Detailed output--debug: Show ffmpeg output (implies --verbose)--no-color: Disable colored output--log-file: Write output to log file
--batch: Process all subdirectories as separate audiobooks--output-pattern: Output filename pattern with{title},{author},{year}placeholders (default:{title}). Used for every book in batch mode and for the output filename in single-book mode.)-r, --recursive: Recursively search for MP3 files--pattern: File pattern to match (default: *.mp3)--exclude: Exclude files matching pattern--when-done {nothing,quit,sleep,shutdown}: Action after conversion finishes (default: none — the application just exits). Works for both single-book and batch conversions. In GUI mode this overrides the Batch tab's "When done" setting for that session only (it is not saved). Sleep and shutdown are skipped with a warning if the platform doesn't support them (e.g. no logind on Linux).
--ffmpeg-path: Custom path to ffmpeg binary--ffprobe-path: Custom path to ffprobe binary--force-reencode: Force re-encoding even if source is already in target format
--gui: Launch graphical user interface--version: Show version information
- Libby Format (
metadata.json): Default format from LibbyRip - FFmetadata (
metadata.txt): FFmpeg metadata format - m4b-tool (
chapters.txt): Format used by m4b-tool and tone - Audacity Labels: Label files from Audacity
The converter auto-detects the format, or you can specify it with:
python PostRipM4b.py /path/to/audiobook --libby-chapters metadata.json
PostRipM4B/
├── PostRipM4b.py # Main converter script
├── chapter_parser.py # Chapter format parsing module
├── requirements.txt # Python dependencies
├── test_all_options.py # Test the CLI command line options
├── test_concat_file.py # Unit tests for concat-list escaping
├── gui/ # GUI components
│ ├── main_window.py # Main GUI window
│ └── chapter_editor.py # Chapter editor dialog
└── README.md # This file
- AudioBookConverter Class: Main conversion engine with parallel processing
- chapter_parser Module: Unified parser for multiple chapter formats
- Config Dataclass: Centralized configuration management
- ProgressTracker Class: Verbosity-controlled output with color support
- GUI Framework: PyQt5-based interface with real-time feedback
- Analysis: Scan MP3 files and detect audio properties
- Metadata Loading: Parse chapter information from supported formats
- Parallel Conversion: Convert MP3 to M4B using multiple workers
- Chapter Timing: Calculate accurate chapter positions based on actual audio duration
- Assembly: Concatenate files with metadata and cover art
- Optimization: Finalize M4B file for compatibility
Contributions are welcome! Please feel free to submit a Pull Request.
` git clone https://github.com/zorin1/PostRipM4B.git cd PostRipM4B python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt
- Follow PEP 8 guidelines
- Use type hints for function signatures
- Include docstrings for public methods
- Keep the dual interface (CLI + GUI) in sync
This project is licensed under the MIT License - see the LICENSE file for details.
- LibbyRip for the initial audiobook extraction
- FFmpeg team for the incredible multimedia framework
- PyQt5 developers for the GUI framework
- ChatGPT/OpenAI and Deepseek for assistance in writing and debugging code (This project was developed with significant AI assistance)
-
"ffmpeg not found"
- Ensure FFmpeg is installed and in your system PATH
- Or specify path with
--ffmpeg-pathoption
-
"No MP3 files found"
- Check your input directory contains MP3 files
- Use
--patternto match different file patterns
-
"Chapter timing inaccurate"
- Use the GUI's chapter editor to adjust timings
- Or manually edit chapter files before conversion
-
Memory issues with large audiobooks
- Reduce worker count with
--workersoption - Ensure sufficient disk space for temporary files
- Reduce worker count with
- Check the verbose output with
--verboseor--debugflags - Enable temporary file retention with
--keep-tempfor inspection - Submit issues on GitHub with detailed error messages
For issues, questions, or feature requests:
- Check the GitHub Issues
- Review the troubleshooting guide above
- Submit a detailed issue report
Happy listening! If you enjoy this tool, please consider starring the repository.
This release makes the Input tab's "MP3 Files Location" field usable as a paste target, and makes the Browse buttons open where you actually are instead of always jumping back to the default music folder.
- Paste a folder into "MP3 Files Location": the field now reacts to a pasted path on its own — no Enter or click elsewhere needed. Within half a second of a paste the folder is validated, its
metadata.json/metadata.txt/chapters.txtis loaded, MP3 analysis starts, and the Output Directory is set to<folder>/m4b. A paste also replaces the existing text instead of splicing the new path onto the end of it. - Pasted paths are cleaned up automatically: paths copied from a file manager are made usable — surrounding quotes (
"C:\Music\Book"),file://URLs, stray whitespace, multi-line clipboard content (the first entry wins) and trailing/or\separators are all handled.~and$HOMEare expanded, and pasting a file inside a book folder uses that folder. If the path doesn't exist, the status bar says so (Source directory not found: …) instead of failing later at conversion time. Text you type by hand is left untouched while you type it. - Browse dialogs remember your location: Browse… for the source opens at the folder currently in the field (or the last folder you chose) rather than the default music dir, and the chapter-file, cover-image and temp-directory pickers do the same — they previously received an invalid start folder and silently fell back to the default whenever the field held a pasted or non-existent path.
- The pasted location is what gets used everywhere: scanning subdirectories, chapter auto-detection, MP3 duration analysis, validation and the conversion config all read the source field through one normalizer, so a quoted or trailing-separator path no longer counts as "no source directory selected".
This release fixes conversions failing for books whose folder or file names contain an apostrophe (e.g. G. Z. Zzz - The Snoozing Dragon's Tail).
- Fixed: apostrophe in paths broke concatenation: the ffmpeg concat list wrapped each file path in single quotes without escaping, so an apostrophe in the input folder or file name terminated the quoted path early — ffmpeg then failed with "Impossible to open '...The Snoozing Dragon'". Paths are now escaped using the concat demuxer's
'\''quoting rule, so any book or author name containing an apostrophe converts correctly. - Improved info glyph: the CLI and GUI log prefix
ℹ(which many terminals render as a bare lowercase "i") was replaced withⓘ. - New unit test suite (
test_concat_file.py): verifies concat-list escaping round-trips through ffmpeg's quoting rules for paths with apostrophes (including multiple files), plus an end-to-end test that runs real ffmpeg against an apostrophe-containing path (skipped when ffmpeg is absent). Run with./.venv/bin/python3 test_concat_file.py.
This release adds a "When done" feature (inspired by HandBrake) that lets the computer take an action automatically after conversions finish — handy for overnight, unattended batch rips.
- New Batch tab option: "After Batch Completion → When done": choose Do Nothing (default), Quit, Sleep, or Shutdown. The selection resets to Do Nothing on each launch (nothing is written to a config file). Sleep and Shutdown are greyed out automatically on systems that don't support them.
- Cancellable countdown before any action fires: when the batch finishes with Quit/Sleep/Shutdown selected, a 60-second countdown dialog appears so you can cancel; otherwise the action runs.
- Confirmation before starting: selecting Sleep or Shutdown asks for confirmation when you start a batch ("The computer will shut down when the batch finishes"). Cancelling a conversion manually never triggers an action.
- New
--when-doneCLI flag:{nothing,quit,sleep,shutdown}, default none (the application simply exits as before). Works in both CLI and GUI modes:- CLI:
python PostRipM4B.py --batch /path/to/books --when-done shutdownshuts the computer down after the last book converts. - GUI: overrides the Batch tab's "When done" setting for that session only.
- CLI:
- Cross-platform power actions (
gui/power_actions.py), mirroring HandBrake's approach per OS:- Windows:
SetSuspendStateAPI (sleep) andshutdown.exe(power off) - macOS: AppleScript via System Events
- Linux: logind over D-Bus (with
CanSuspend/CanPowerOffcapability checks; falls back frombusctltodbus-send)
- Windows:
This release makes the temporary-file directory smarter so temporary files stay next to the audiobook being processed.
- Temp directory defaults to the input folder: when
--temp-diris not given, temporary files now live in<input_dir>/tmp(the folder of the audiobook being converted) instead of a global default. This keeps temp files with the book and avoids cross-book collisions. - Explicit
--temp-diris honored as a fixed override: any value you pass is used as-is and is no longer overridden. In single-book and batch mode alike, each book derives its own<folder>/tmpunless you specify one manually. - GUI temp-directory field only used as an override: the GUI now treats the "Temp Directory" field strictly as a manual override (cleared field = derive per-book from the input dir). Batch mode no longer forces/ignores it separately.
This release fixes batch processing and subdirectory scanning for audiobooks that span multiple folders or discs.
- One-level subdirectory scanning: "Search subdirectories for MP3 files" (GUI Input tab / CLI
--recursive) scans the book folder plus its immediate subdirectories — exactly the layout of a multi-CD book likemultiple/CD01,multiple/CD02. Deeper nesting is intentionally not searched. Single-book validation uses the same scan, so a book whose MP3s live in subdirectories is no longer rejected with "No MP3 files found". - Batch finds books at any depth: batch scanning (GUI Scan Subdirectories and CLI
--batch --recursive) walks the whole source tree and lists every audiobook it finds — for example, pointing it at~/MusiclistsHarry Potter/Book1,Harry Potter/Book2,Harry Potter/Book3, even though the books sit below a series folder. A folder whose audio lives in its immediate subdirectories (e.g.Book2/CD01,Book2/CD02) is treated as ONE book. Container folders (likeHarry Potteritself) are not listed as books. The disc subdirectories of a multi-CD book are still shown in the GUI, unchecked, so you can convert a single disc on its own. When subdirectory search is off, only the source's immediate subfolders that directly contain audio are listed.
This release stops writing a bogus year tag and adds full narrator support.
- Year is no longer forced to the current year: previously the release year defaulted to today's date and was always written as a
datetag — even when the year was unknown, and it silently overwrote a year present in the metadata file. Now the year is only written to the M4B when it's explicitly provided: via--year, in a metadata file, or entered in the GUI. When it's missing, nodatetag is written at all. The GUI's year field now defaults to "Not specified" instead of today's year. - Narrator support added: the narrator (e.g. from a Libby
metadata.jsoncreatorentry with rolenarrator) is now written to the M4B instead of being silently discarded. Added a new--narratorCLI flag and a Narrator field in the GUI's Metadata tab. When no narrator is present, no narrator tag is written. Uses existing tags (----:com.apple.iTunes:narratorand----:com.apple.iTunes:LYRICIST) via mutagen. - Metadata precedence now matches batch mode: values from the metadata/chapter file take precedence over command-line values, which are used only to fill in fields the file doesn't provide. This keeps batch processing correct (each book uses its own file's metadata) and fixes CLI/GUI overrides being silently discarded in the GUI.
- GUI no longer carries stale metadata between books: switching the source directory to a book with no metadata file now clears the previous book's values and shows the CLI/GUI defaults (e.g.
--narrator) instead of the previous book's narrator/title/author. - Chapter Information updates when switching books: switching to a book with no metadata now clears the Chapter Information section and disables the Edit Chapters button instead of leaving the previous book's chapters on screen. Late MP3-analysis results from a previously selected book are ignored so they can't repopulate the display.
- Edit Chapters always available: the Edit Chapters button is now always enabled, including for books with no metadata file — opening it builds chapters from the current fields so you can create and edit chapters from scratch. The editor no longer requires an author, so chapters can be used even when the author is unknown.
- Title falls back to the book's directory name: the title is now resolved in the order metadata file →
--title→ the name of the directory containing the MP3 files (previously, chapter-only files likechapters.txtproduced the file's name, e.g. "chapters", as the title). Album and Sort Name are still populated from the resolved title when not set, and the GUI now shows this folder-name fallback in the Title/Album/Sort Name fields instead of leaving them blank. - Batch processing is always available: the "Process all subdirectories" checkbox was removed — the Batch tab's Scan Subdirectories button and list are always enabled, and batch mode activates simply by checking folders in the list. CLI
--batchnow auto-populates the batch list when a source directory is set.
This release fixes output filename handling and improves recursive file discovery for books that span multiple folders.
- Blank placeholders in output patterns:
{author}and{year}now expand to blank when the value is missing (e.g.{title}-{year}with no year givestitle-.m4binstead oftitle-title.m4b).{title}still falls back to the folder name. - Recursive batch scanning: the Batch tab's Scan Subdirectories (and CLI
--batch) now search subdirectories recursively, so nested book folders likeAlbum1/Album2are detected even when the audio lives one or more levels deep. (In 1.4 the search is refined to find books at any depth and group multi-CD folders into a single book.) - Correct file ordering for multi-directory books: when Search subdirectories for MP3 files is enabled, files are now sorted by full path rather than filename alone, so books laid out as
CD1,CD2,CD3are assembled in the right order instead of being interleaved.
This release makes batch processing fully functional in both the GUI and the CLI.
- GUI batch mode is now working: the "🔄 Batch" tab's Scan Subdirectories, Select All, and Deselect All now drive the actual conversion. Each selected folder is converted as its own independent audiobook, one at a time, with progress logs prefixed per book (e.g.
[bookname 2/5]). - CLI
--batchis now real: previously the--batchflag was stored but never used. It now expands the input directory into its subdirectories and runs a separate conversion per folder. - Per-folder output: each book writes to its own
<folder>/m4bdirectory. The Output Directory setting (GUI Input tab /--output-dir) is ignored in batch mode, so books never collide. - Batch-specific metadata: metadata-tab values are ignored in batch mode. Each folder auto-detects its own metadata/chapter file (
metadata/metadata.json,metadata.txt,chapters.txt, etc.). When none is found — or fields are missing — the folder name is used as the Title/Album/Sort Name fallback, with Track = 1 and Media Type = 2. A cover image is auto-detected per folder. - New
--output-patternflag ({title},{author},{year}): controls the output filename for every book (GUI and CLI), mirroring the Batch tab's Output Filename Pattern field. - Batch does not stop on failure: if one book fails, the remaining books still convert, and a summary ("N of Y books completed successfully") is reported at the end.
- Single-book conversion behavior is unchanged.
- Fixed CLI metadata overrides (
--track-num,--album,--sort-name,--media-type) being dropped when chapter timing adjustments were applied during conversion - Fixed GUI not populating
--track-num,--sort-name,--album, and--media-typevalues from CLI args in the Metadata tab - Fixed GUI
--titlenot automatically defaulting Album and Sort Name fields when--albumand--sort-nameare not explicitly passed
This release includes several improvements and refinements to enhance your audiobook conversion experience:
- Improved chapter parsing accuracy across all supported formats
- Enhanced GUI responsiveness and usability
- Optimized parallel processing for faster conversions
- Better error handling and logging for troubleshooting
- Updated dependencies for improved stability and compatibility
- Minor bug fixes and performance enhancements
Thank you for using PostRipM4B! Please continue to provide feedback and report issues on GitHub.