This fork of calibre2komga adds a powerful Virtual Filesystem (FUSE) feature. Instead of copying thousands of files and wasting disk space, this tool can "mount" your Calibre library into a format that Komga understands perfectly.
- Zero-Copy Mirroring: Use FUSE to expose your Calibre library to Komga without duplicating a single byte.
- Modular Architecture: Refactored for better maintenance and separate components for database parsing, exporting, and mounting.
- Docker Ready: Includes specific support for
--allow-otherand clear instructions for Docker/Ubuntu environments.
π Read the FUSE Setup & Mount Guide (USAGE_FUSE.md)
The FUSE feature requires libfuse2. On modern Ubuntu versions (22.04+), install it with:
sudo apt update
# Ubuntu 22.04:
sudo apt install libfuse2
# Ubuntu 24.04:
sudo apt install libfuse2t64It is recommended to use a virtual environment:
# Create venv
python3 -m venv venv
# Activate venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtWhile I like Calibre (and still plan to use it for ingesting books), I grew dissatisfied with Calibre-Web (and Calibre-Web-Automated). I liked Komga and wanted to switch, but didn't want to spend time painfully migrating my library to the structure Komga likes. So I asked my buddy Claude(.ai) to help me write a migration script. After some back and forth and tweaks, this is the result. So yes, it's 100% AI coded, but 1) it's non-desctructive to your Calibre library and 2) it's at least been tested by me a bit. That being said, if you see something/run into issues, by all means raise an issue and we'll work on it.
A Python script that migrates ebooks from Calibre's folder structure to Komga's expected format, making it easy to transition your ebook library to Komga's comic/ebook server.
- Backup First: Always backup your libraries before migration
- Non-destructive: Original Calibre library remains unchanged
- File Conflicts: Existing files in destination are skipped with warnings
- Series Only: Books without
.epubor.kepubformats are skipped (Komga only reads epub files so no need to migrate the rest) - Metadata: Only ebook files are copied; metadata and cover files are excluded
This script reads Calibre's metadata database to accurately organize books by series and converts the folder structure from Calibre's Author/Title/files format to Komga's flat Series/files format.
π Calibre Library/
βββ π Brandon Sanderson/
β βββ π The Way of Kings (45)/
β β βββ π The Way of Kings.epub
β βββ π Words of Radiance (22)/
β β βββ π Words of Radiance.epub
β βββ π Warbreaker (178)/
β βββ π Warbreaker.epub
π Komga Library/
βββ π Brandon Sanderson - The Stormlight Archive/
β βββ π Volume 01 - The Way of Kings.epub
β βββ π Volume 02 - Words of Radiance.epub
βββ π Brandon Sanderson/
βββ π Warbreaker.epub
- β Database-driven: Uses Calibre's SQLite database for accurate series detection
- β Series organization: Groups books properly using Calibre's series metadata
- β Volume numbering: Maintains correct order using series index from Calibre
- β Title cleaning: Removes Calibre's auto-generated numbering suffixes (e.g., "(84)")
- β
Format filtering: Only migrates
.epuband.kepubfiles - β Dry run mode: Preview changes before migration
- β Author filtering: Migrate specific authors only
- β Cross-platform: Works on Windows, macOS, and Linux
- β Safe migration: Preserves original files, copies to new location
- β Virtual Filesystem (NEW): Mount your library as a virtual drive using FUSE (Linux only, zero disk space used!)
- Python 3.6 or higher
- Access to a Calibre library folder
- Destination folder for Komga library
fusepy(for the optional FUSE mount feature)
- Download the script files (
calibre2komga.py,calibre_core.py, etc.) - Ensure Python 3.6+ is installed on your system
- For the FUSE mount feature, install dependencies:
pip install fusepy
This "tricks" Komga into thinking the files are in its preferred structure without actually copying them.
# Basic mount
python3 calibre2komga.py mount /path/to/calibre /mnt/komga_virtual
# Mount with Audiobook Injection (New!)
python3 calibre2komga.py mount /path/to/calibre /mnt/komga_virtual \
--audiobook-column "audiobook_path" \
--audiobook-base-path "/path/to/audiobooks"
# For Docker support (requires editing /etc/fuse.conf)
python3 calibre2komga.py mount /path/to/calibre /mnt/komga_virtual --allow-otherSee USAGE_FUSE.md for detailed instructions on backgrounding and permissions.
python3 calibre2komga.py export /path/to/calibre /path/to/komgaThe virtual filesystem can dynamically merge audiobook folders into your EPUB files on the fly. This allows media servers like Komga to "see" audiobook files (like .mp3 or .m4a) as if they were stored inside the EPUB archive in a subfolder named audiobook/.
- Calibre Side: Create a custom column in Calibre (type: "Text") to store the relative path to the book's audiobook folder.
- Filesystem Side: Ensure your audiobooks are stored in a consistent root directory.
- Mount Command: Use the flags below to tell the script how to link them.
What happens if flags are missing?
- If
--audiobook-columnis not provided, the script behaves normally (no audio injection). - If
--audiobook-extsis omitted, it defaults to.mp3,.m4a. - If a book has no value in the specified custom column, it is served as a regular EPUB.
| Option | Description |
|---|---|
calibre_path |
Path to your Calibre library directory (required) |
komga_path |
Path to your Komga library directory (required, will be created if doesn't exist) |
--dry-run |
Show what would be migrated without copying files |
--author "Name" |
Filter migration to specific author (case insensitive partial match) |
--verbose |
Enable detailed logging output |
--allow-other |
Allow other users to access the mount (required for Docker) |
--audiobook-column |
Name of the Calibre custom column containing the audiobook relative path |
--audiobook-base-path |
Absolute path to the root folder where audiobooks are stored |
--audiobook-exts |
Comma-separated list of allowed audio extensions (default: .mp3,.m4a) |
- Reads Calibre Database: Connects to
metadata.dbto extract book metadata, series information, and series indices - Series Detection: Uses Calibre's series metadata for accurate grouping, falls back to title pattern matching for standalone books
- Folder Structure: Creates series folders and places files directly inside (no subfolders)
- File Naming: Renames files to include volume information for series books
- Format Filtering: Only processes
.epuband.kepubfiles
- Folder:
Author - Series Name - Files:
Volume XX - Book Title.epub
Example: Brandon Sanderson - Mistborn/Volume 01 - The Final Empire.epub
- Folder:
Author Name - Files:
Book Title.epub
Example: Brandon Sanderson/Warbreaker.epub
The script provides detailed statistics after completion:
Migration Summary:
Total books found: 1,247
Books migrated: 1,198
Books skipped: 45
Errors: 4
Success rate: 96.1%
- Ensure you're pointing to the root Calibre library folder
- The folder should contain a
metadata.dbfile
- Book only has formats other than
.epubor.kepub - Consider converting books in Calibre first if needed
- Ensure you have read access to Calibre library
- Ensure you have write access to destination folder
A standalone utility that virtually merges an existing ZIP file with an external directory. It presents them as a single valid ZIP file via FUSE. This is used by the main script to inject audiobooks into EPUB files on the fly.
python3 virtual_zip.py /path/to/base.zip /path/to/extra_files /path/to/mount_dir --target-dir "audiobook" --exts ".mp3,.m4a"We have included a test data setup to verify the engine works:
-
Create Test Data:
mkdir -p test_data/extra python3 -c "import zipfile; z = zipfile.ZipFile('test_data/base.zip', 'w'); z.writestr('original.txt', 'Original content'); z.close()" echo "Audio 1" > test_data/extra/audio1.mp3 echo "Audio 2" > test_data/extra/audio2.m4a mkdir -p test_mount
-
Run the Virtual Mount:
source venv/bin/activate python3 virtual_zip.py test_data/base.zip test_data/extra test_mount -
Verify (In another terminal):
# List the virtual ZIP content unzip -l test_mount/base.zip # Verify integrity (CRC check) unzip -t test_mount/base.zip # Extract to verify data mkdir -p extracted_test && unzip test_mount/base.zip -d extracted_test
Disclaimer: This script is not officially affiliated with Calibre or Komga projects. Use at your own risk and always backup your data before migration.