View Single Post
Old 01-03-2011, 05:03 PM   #4
ATDrake
Wizzard
ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.ATDrake ought to be getting tired of karma fortunes by now.
 
Posts: 6,663
Karma: 16372659
Join Date: Mar 2010
Location: Roundworld
Device: Kindle 2 International & Sony PRS-T1
Well, I just tested a couple of my own Mobi books, and it turns out that most of them which have existing TOCs in the actual text can be easily regexp'd to give you an easy base NCX to start with. Enough so that most of the work is done for you and you only have to do minor clean up.

So, provided someone properly filled out the HTML TOC on your Mobi, unpack the entire book using the Python utility in this post here, copy all the <p><a href="#filepos">Chapter X</a></p> stuff in the TOC section into a new text document, and run some variant of the following regexp upon it:
Code:
<p><a href="\#(filepos\d+)"><font color="inherit">([0-9a-zA-z|,| |:|?|!]+)</font></a></p>
to
Code:
<navPoint id="$1" playOrder="">
	<navLabel><text>$2</text></navLabel>
	<content src="\#$1" />
	</navPoint>
Some unpacked mobi files don't use the <font> tag, some add other cruft, so adjust the first example as necessary. The important parts are the #filepos and the chapter name.

Then do a search/replace on the <content src> to reference your unpacked file, add in the appropriate headers and such to the NCX, fill in the PlayOrder numbers, reference the new NCX in the extracted OPF, regenerate the Mobi, and you should be good to go.

Last edited by ATDrake; 01-03-2011 at 05:44 PM. Reason: Forgot a trailing slash.
ATDrake is offline   Reply With Quote