I almost hesitate to post this here, because it’s not particularly technically interesting, but this blog is partially notes for my future self. I frequently read ebooks on my phone in the epub format. Epub has gone through a few major versions and some epubs now don’t work with major epub readers. On my old laptop, I had a script called fix_ebook.sh
that would attempt a number of common fixes, like upgrading the format version and converting the epub to mobi and back. Unfortunately, I lost that script, but fortunately, ChatGPT one-shotted a new version for me! The new version is much more professionally formatted than the old version and has optional round-trip mobi conversion (default off). Default usage is:
./fix_ebook.sh my_book.epub
And round-trip conversion with:
./fix_ebook.sh -r my_ebook.epub
Both will produce a my_ebook.fixed.epub. This script has Calibre as a dependency (Calibre provides CLI conversion tools).
You can get the script here