Skip to content

Commit

Permalink
rename mobi7 components to toc.ncx, book.html, content.opf to prevent…
Browse files Browse the repository at this point in the history
… bugs in opf generation

add in mobiml2xhtml.py for future use in converting old mobi7 ml to something closer to xhtml
Authors: KevinH
  • Loading branch information
Kevin Hendricks committed Oct 14, 2014
1 parent 91d3e28 commit d992107
Show file tree
Hide file tree
Showing 5 changed files with 550 additions and 18 deletions.
7 changes: 4 additions & 3 deletions lib/kindleunpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
# 0.73 faster mobi split, numerous bug fixes in mobi_k8proc, mobi_header, mobi_opf, mobi_k8resc, etc
# 0.74 added refines metadata, fixed language code in ncx and title in nav, added support for opf: from refines
# 0.75 much improved dictioanry support including support for multiple inflection sections, minor mobi_opf fixes

# 0.76 rename mobi7 pieces to book.html, toc.ncx, and content.opf to prevent bug in opf

DUMP = False
""" Set to True to dump all possible information. """
Expand Down Expand Up @@ -589,7 +589,8 @@ def processMobi7(mh, metadata, sect, files, imgnames):

# write the proper mobi html
fileinfo=[]
fname = files.getInputFileBasename() + '.html'
# fname = files.getInputFileBasename() + '.html'
fname = 'book.html'
fileinfo.append([None,'', fname])
outhtml = os.path.join(files.mobi7dir, fname)
open(pathof(outhtml), 'wb').write(srctext)
Expand Down Expand Up @@ -898,7 +899,7 @@ def main():
global DUMP
global WRITE_RAW_DATA
global SPLIT_COMBO_MOBIS
print "KindleUnpack v0.75"
print "KindleUnpack v0.76"
print " Based on initial mobipocket version Copyright © 2009 Charles M. Hannum <[email protected]>"
print " Extensive Extensions and Improvements Copyright © 2009-2014 "
print " by: P. Durrant, K. Hendricks, S. Siebert, fandrieu, DiapDealer, nickredding, tkeo."
Expand Down
7 changes: 5 additions & 2 deletions lib/mobi_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,11 @@ def addValue(name, value):
addValue(name, str(value))
elif size == 12:
value, = struct.unpack('>L',content)
# handle special case of missing CoverOffset
if id != 201 or value != 0xffffffff:
# handle special case of missing CoverOffset or missing ThumbOffset
if id == 201 or id == 202:
if value != 0xffffffff:
addValue(name, str(value))
else:
addValue(name, str(value))
else:
print "Warning: Bad key, size, value combination detected in EXTH ", id, size, content.encode('hex')
Expand Down
5 changes: 3 additions & 2 deletions lib/mobi_ncx.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def writeNCX(self, metadata):
htmlname = os.path.basename(self.files.outbase)
htmlname += '.html'
xml = self.buildNCX(htmlname, metadata['Title'][0], metadata['UniqueID'][0], metadata.get('Language')[0])
#write the ncx file
ncxname = os.path.join(self.files.mobi7dir, self.files.getInputFileBasename() + '.ncx')
# write the ncx file
# ncxname = os.path.join(self.files.mobi7dir, self.files.getInputFileBasename() + '.ncx')
ncxname = os.path.join(self.files.mobi7dir, 'toc.ncx')
open(pathof(ncxname), 'wb').write(xml)


Expand Down
25 changes: 14 additions & 11 deletions lib/mobi_opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,19 @@ def buildOPFManifest(self, ncxname, navname=None):
'.gif' : 'image/gif',
'.svg' : 'image/svg+xml',
'.xhtml': 'application/xhtml+xml',
'.html' : 'text/x-oeb1-document', # for mobi7
'.pdf' : 'application/pdf', # for azw4(print replica textbook)
'.html' : 'text/html', # for mobi7
'.pdf' : 'application/pdf', # for azw4(print replica textbook)
'.ttf' : 'application/x-font-ttf',
'.otf' : 'application/x-font-opentype', # replaced?
#'.otf' : 'application/vnd.ms-opentype', # [OpenType] OpenType fonts
#'.woff' : 'application/font-woff', # [WOFF] WOFF fonts
#'.smil' : 'application/smil+xml', # [MediaOverlays301] EPUB Media Overlay documents
#'.pls' : 'application/pls+xml', # [PLS] Text-to-Speech (TTS) Pronunciation lexicons
'.css' : 'text/css',
#'.html' : 'text/x-oeb1-document', # for mobi7
#'.otf' : 'application/vnd.ms-opentype', # [OpenType] OpenType fonts
#'.woff' : 'application/font-woff', # [WOFF] WOFF fonts
#'.smil' : 'application/smil+xml', # [MediaOverlays301] EPUB Media Overlay documents
#'.pls' : 'application/pls+xml', # [PLS] Text-to-Speech (TTS) Pronunciation lexicons
#'.mp3' : 'audio/mpeg',
#'.mp4' : 'audio/mp4',
#'.js' : 'text/javascript', # not supported in K8
'.css' : 'text/css'
#'.mp4' : 'video/mp4',
#'.js' : 'text/javascript', # not supported in K8
}
spinerefs = []

Expand Down Expand Up @@ -467,7 +468,8 @@ def buildMobi7OPF(self):
opf_metadata = self.buildOPFMetadata(metadata_tag)
data += opf_metadata
if self.has_ncx:
ncxname = self.files.getInputFileBasename() + '.ncx'
# ncxname = self.files.getInputFileBasename() + '.ncx'
ncxname = 'toc.ncx'
else:
ncxname = None
[opf_manifest, spinerefs] = self.buildOPFManifest(ncxname)
Expand Down Expand Up @@ -527,7 +529,8 @@ def writeOPF(self, has_obfuscated_fonts=False):
return self.BookId
else:
data = self.buildMobi7OPF()
outopf = os.path.join(self.files.mobi7dir, self.files.getInputFileBasename() + '.opf')
# outopf = os.path.join(self.files.mobi7dir, self.files.getInputFileBasename() + '.opf')
outopf = os.path.join(self.files.mobi7dir, 'content.opf')
open(pathof(outopf), 'wb').write(data)
return 0

Expand Down
Loading

0 comments on commit d992107

Please sign in to comment.