mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
KF8 Output: Split on page breaks to produce KF8 files that work better with viewers that dont support CSS page breaks. Also remove no longer used MOBI_UNPACK code from MOBI input
This commit is contained in:
parent
c7ff97e1a0
commit
7468f24996
@ -7,22 +7,6 @@ import os
|
|||||||
|
|
||||||
from calibre.customize.conversion import InputFormatPlugin
|
from calibre.customize.conversion import InputFormatPlugin
|
||||||
|
|
||||||
def run_mobi_unpack(stream, options, log, accelerators):
|
|
||||||
from mobiunpack.mobi_unpack import Mobi8Reader
|
|
||||||
from calibre.customize.ui import plugin_for_input_format
|
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
|
||||||
|
|
||||||
wdir = PersistentTemporaryDirectory('_unpack_space')
|
|
||||||
m8r = Mobi8Reader(stream, wdir)
|
|
||||||
if m8r.isK8():
|
|
||||||
epub_path = m8r.processMobi8()
|
|
||||||
epub_input = plugin_for_input_format('epub')
|
|
||||||
for opt in epub_input.options:
|
|
||||||
setattr(options, opt.option.name, opt.recommended_value)
|
|
||||||
options.input_encoding = m8r.getCodec()
|
|
||||||
return epub_input.convert(open(epub_path,'rb'), options,
|
|
||||||
'epub', log, accelerators)
|
|
||||||
|
|
||||||
class MOBIInput(InputFormatPlugin):
|
class MOBIInput(InputFormatPlugin):
|
||||||
|
|
||||||
name = 'MOBI Input'
|
name = 'MOBI Input'
|
||||||
@ -34,14 +18,6 @@ class MOBIInput(InputFormatPlugin):
|
|||||||
accelerators):
|
accelerators):
|
||||||
self.is_kf8 = False
|
self.is_kf8 = False
|
||||||
|
|
||||||
if os.environ.get('USE_MOBIUNPACK', None) is not None:
|
|
||||||
pos = stream.tell()
|
|
||||||
try:
|
|
||||||
return run_mobi_unpack(stream, options, log, accelerators)
|
|
||||||
except Exception:
|
|
||||||
log.exception('mobi_unpack code not working')
|
|
||||||
stream.seek(pos)
|
|
||||||
|
|
||||||
from calibre.ebooks.mobi.reader.mobi6 import MobiReader
|
from calibre.ebooks.mobi.reader.mobi6 import MobiReader
|
||||||
from lxml import html
|
from lxml import html
|
||||||
parse_cache = {}
|
parse_cache = {}
|
||||||
|
@ -174,6 +174,13 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
add_fonts=create_kf8)
|
add_fonts=create_kf8)
|
||||||
self.check_for_periodical()
|
self.check_for_periodical()
|
||||||
|
|
||||||
|
if create_kf8:
|
||||||
|
# Split on pagebreaks so that the resulting KF8 works better with
|
||||||
|
# calibre's viewer, which does not support CSS page breaks
|
||||||
|
from calibre.ebooks.oeb.transforms.split import Split
|
||||||
|
Split()(self.oeb, self.opts)
|
||||||
|
|
||||||
|
|
||||||
kf8 = self.create_kf8(resources, for_joint=mobi_type=='both'
|
kf8 = self.create_kf8(resources, for_joint=mobi_type=='both'
|
||||||
) if create_kf8 else None
|
) if create_kf8 else None
|
||||||
if mobi_type == 'new':
|
if mobi_type == 'new':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user