Apple - How to convert an epub package to regular epub?

FWIW, here's a shell command that works:

 cd my-broken.epub

 # iTunes/Books seems to add a file 
 # 'iTunesMetadata.plist', and it produces a warning.
 # May also contain private data, so better delete it.

 rm iTunesMetadata.plist 

 zip -X -r ../fixed.epub mimetype *

As far as I can tell, compression does not need to be deactivated (-0). epubcheck has no complaints. There might be differences between versions of the epub spec, however. My test was with an epub 3.0 file.


Reproduction of the problem:

  1. A ePub file named, say, book.epub is a file (-rw-r--r--).
  2. Open book.epub using iBooks app.
  3. Take out the cached file stored in ~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/, which has been renamed to another name such as A22DFAF7E75C21D979C375B1AD07008F.epub and becomes a directory (drwxr-xr-x@).

Steps of the work-around that works on my Mac:

  1. Change extension of A22DFAF7E75C21D979C375B1AD07008F.epub from .epub to .zip.
  2. Go into the zip package and zip up all the contents inside into a new .zip file, say, Archive.zip.
  3. Drag out the new .zip file and change extension back to .epub.
  4. The Archive.epub file is a file (-rw-r--r--).

An ePub file is essentially just a zipped folder, though it has a mimetype file inside which apparently needs to not be compressed.

This would imply that it's not completely straightforward to recreate with a simple zip app. However, it may be simpler than that.
Let's assume nothing has actually unpacked it, merely got confused about how to deal with it. Work on a copy.

Two things to try...

  1. Try just renaming it, change .epub to .zip, then change it back again, see if it's recognised correctly.

  2. Open it in Calibre
    You than have a myriad ways to deal with it, simplest is see if it can talk to your ebook reader via OPDS. Calibre can run its own local server on your wifi & you can copy books over very simply.
    If still no joy, get Calibre to convert it to an ePub [again] This is a great method for fixing a file, as it can re-examine it, fix fonts, bad hyphenations, all kinds of issues.

Calibre itself is too big a subject to really cover in a simple QA, but there are reams of data about it on the site itself & at http://www.mobileread.com/forums/ including sections for most major e-readers too.

Tags:

Epub

Books