Friday, December 23, 2011

Command Line Calibre

‹prev | My Chain | next›

I spend a good chunk of time today researching. I had hoped to find an easy solution that would allow me to create and modify the "exth" header in mobi files. If I can just do that, then I can set the "cdetype" in that header to "EBOK", which would signal to Kindles that books like Recipes with Backbone are ebooks and not "personal documents" ("PDOC").

Last night I was able to get this working with the GUI tool Calibre. The problem is that it is a GUI tool. A big appeal of git-scribe is that automates so much of the ebook chain. In my fork of git-scribe, I have it to the point that I can generate PDF, epub and mobi versions of a book and zip them all into a single file with just one command. I do not relish adding a manual, GUI step to that process.

The best I can come up with for command-line solutions is mobiperl. It seems like it would do the trick -- it was the inspiration for Calibre's EBOK support. But I am not going to pursue that. There are already an alarming number of dependencies in git-scribe, I do not think adding perl and all of mobiperl's requirements is going to help.

In ruby-land (git-scribe is written in ruby), there is the mobi gem, but that is for reading mobi, not writing. And it does not seem to be exth-aware. I could try writing my own, but that just feels like too much of a rabbit hole.

So it seems as though I am stuck with Calibre. It turns out that there is a set of command-line tools that are installed along with the GUI. One in particular, ebook-meta seems like it could be of some use, except... it does not support updating "cdetype" field in a mobi.

Another command-line tool installed along with Calibre is ebook-convert. It does not support editing the cdetype either, but I have already used the GUI to always generate EBOK output.

So I give the command a try, converting the mobi version of Recipes with Backbone to... mobi:
➜  output git:(master) ebook-convert book.mobi book_ebok.mobi
1% Converting input to HTML...
InputFormatPlugin: MOBI Input running
on /home/cstrom/repos/backbone-recipes/output/book.mobi
Parsing all content...
Forcing Recipes_with_Backbone.html into XHTML namespace
34% Running transforms on ebook...
Merging user specified metadata...
Detecting structure...
        Detected chapter: 1. Who Should Read this Book
        Detected chapter: 3. How this Book is Organized
        Detected chapter: Chapter 1. Writing Client Side Apps (Without Backb
        Detected chapter: Chapter 2. Writing Backbone Applications
        Detected chapter: Chapter 3. Namespacing
        Detected chapter: Chapter 4. View Templates with Underscore.js
        Detected chapter: Chapter 5. Instantiated View
        Detected chapter: Chapter 6. Collection View
        Detected chapter: Chapter 7. View Signature
        Detected chapter: Chapter 8. Fill-In Rendering
        Detected chapter: Chapter 9. Actions and Animations
        Detected chapter: Chapter 10. Reduced Models and Collections
        Detected chapter: Chapter 11. Non-REST Models
        Detected chapter: Chapter 12. Changes Feed
        Detected chapter: Chapter 13. Pagination and Search
        Detected chapter: Chapter 14. Constructor Route
        Detected chapter: Chapter 15. Router Redirection
        Detected chapter: Chapter 16. Evented Routers
        Detected chapter: Chapter 17. Object References in Backbone
        Detected chapter: Chapter 18. Custom Events
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Trimming 'images/00007.jpg' from manifest
Creating MOBI Output...             
67% Creating MOBI Output
Generating in-line TOC...
Applying case-transforming CSS...
Rasterizing SVG images...
Converting XHTML to Mobipocket markup...
Serializing markup content...
  Compressing markup content...
Generating flat CTOC ...
  CNCX utilization: 1 record, 0% full
Indexing navPoints ...
Generating INDX ...
Serializing images...
MOBI output written to /home/cstrom/repos/backbone-recipes/output/book_ebok.mobi
Output saved to   /home/cstrom/repos/backbone-recipes/output/book_ebok.mobi
Hrm... it really seems to do quite a bit of changing and re-arranging of things. I had expected, based on a cursory reading of the mobi-to-mobi options for ebook-convert that it would do less.

Still, it does the job. When I copy the generated book back to my Kindle Fire, it shows up under the "Books" section rather than the "Documents" section.

Hrm... perhaps I can add an optional "clean-up" step to git-scribe that can invoke an arbitrary command-line script. I cannot explicitly include Calibre since it requires the GUI configuration from last night. But first, I think, I need to compare the output from ebook-convert with the original git-scribe mobi. I worked hard three months ago to get it just right. I will pick back up with that tomorrow.


Day #243

No comments:

Post a Comment