mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New MOBI output: Allow calibre to convert OEB documents with a toc.ncx conforming to the kindlegen periodical specification into periodicals
This commit is contained in:
parent
4270605335
commit
1297576ee2
@ -295,7 +295,9 @@ class Indexer(object): # {{{
|
|||||||
self.log = oeb.log
|
self.log = oeb.log
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
|
||||||
self.is_periodical = opts.mobi_periodical
|
self.is_periodical = self.detect_periodical()
|
||||||
|
self.log('Generating MOBI index for a %s'%('periodical' if
|
||||||
|
self.is_periodical else 'book'))
|
||||||
self.is_flat_periodical = False
|
self.is_flat_periodical = False
|
||||||
if opts.mobi_periodical:
|
if opts.mobi_periodical:
|
||||||
periodical_node = iter(oeb.toc).next()
|
periodical_node = iter(oeb.toc).next()
|
||||||
@ -317,6 +319,28 @@ class Indexer(object): # {{{
|
|||||||
|
|
||||||
self.calculate_trailing_byte_sequences()
|
self.calculate_trailing_byte_sequences()
|
||||||
|
|
||||||
|
def detect_periodical(self): # {{{
|
||||||
|
for node in self.oeb.toc.iterdescendants():
|
||||||
|
if node.depth() == 1 and node.klass != 'article':
|
||||||
|
self.log.debug(
|
||||||
|
'Not a periodical: Deepest node does not have '
|
||||||
|
'class="article"')
|
||||||
|
return False
|
||||||
|
if node.depth() == 2 and node.klass != 'section':
|
||||||
|
self.log.debug(
|
||||||
|
'Not a periodical: Second deepest node does not have'
|
||||||
|
' class="section"')
|
||||||
|
return False
|
||||||
|
if node.depth() == 3 and node.klass != 'periodical':
|
||||||
|
self.log.debug('Not a periodical: Third deepest node'
|
||||||
|
' does not have class="periodical"')
|
||||||
|
return False
|
||||||
|
if node.depth() > 3:
|
||||||
|
self.log.debug('Not a periodical: Has nodes of depth > 3')
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
# }}}
|
||||||
|
|
||||||
def create_index_record(self): # {{{
|
def create_index_record(self): # {{{
|
||||||
header_length = 192
|
header_length = 192
|
||||||
buf = StringIO()
|
buf = StringIO()
|
||||||
@ -630,6 +654,7 @@ class Indexer(object): # {{{
|
|||||||
return indices
|
return indices
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# TBS {{{
|
||||||
def calculate_trailing_byte_sequences(self):
|
def calculate_trailing_byte_sequences(self):
|
||||||
self.tbs_map = {}
|
self.tbs_map = {}
|
||||||
found_node = False
|
found_node = False
|
||||||
@ -670,6 +695,7 @@ class Indexer(object): # {{{
|
|||||||
|
|
||||||
def get_trailing_byte_sequence(self, num):
|
def get_trailing_byte_sequence(self, num):
|
||||||
return self.tbs_map[num].bytestring
|
return self.tbs_map[num].bytestring
|
||||||
|
# }}}
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user