mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
...
This commit is contained in:
parent
26b320c7cf
commit
c1967a935d
@ -19,7 +19,7 @@ from calibre import CurrentDir
|
|||||||
|
|
||||||
exe = 'kindlegen.exe' if iswindows else 'kindlegen'
|
exe = 'kindlegen.exe' if iswindows else 'kindlegen'
|
||||||
|
|
||||||
def refactor_opf(opf, is_periodical):
|
def refactor_opf(opf, is_periodical, toc):
|
||||||
with open(opf, 'rb') as f:
|
with open(opf, 'rb') as f:
|
||||||
root = etree.fromstring(f.read())
|
root = etree.fromstring(f.read())
|
||||||
if is_periodical:
|
if is_periodical:
|
||||||
@ -27,11 +27,11 @@ def refactor_opf(opf, is_periodical):
|
|||||||
xm = etree.SubElement(metadata, 'x-metadata')
|
xm = etree.SubElement(metadata, 'x-metadata')
|
||||||
xm.tail = '\n'
|
xm.tail = '\n'
|
||||||
xm.text = '\n\t'
|
xm.text = '\n\t'
|
||||||
mobip = etree.SubElement(xm, attrib={'encoding':"utf-8",
|
mobip = etree.SubElement(xm, 'output', attrib={'encoding':"utf-8",
|
||||||
'content-type':"application/x-mobipocket-subscription-magazine"})
|
'content-type':"application/x-mobipocket-subscription-magazine"})
|
||||||
mobip.tail = '\n'
|
mobip.tail = '\n'
|
||||||
with open(opf, 'wb') as f:
|
with open(opf, 'wb') as f:
|
||||||
f.write(etree.tostring(root, method='xml', encodin='utf-8',
|
f.write(etree.tostring(root, method='xml', encoding='utf-8',
|
||||||
xml_declaration=True))
|
xml_declaration=True))
|
||||||
|
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ def refactor_guide(oeb):
|
|||||||
def run_kindlegen(opf, log):
|
def run_kindlegen(opf, log):
|
||||||
log.info('Running kindlegen on MOBIML created by calibre')
|
log.info('Running kindlegen on MOBIML created by calibre')
|
||||||
oname = os.path.splitext(opf)[0] + '.mobi'
|
oname = os.path.splitext(opf)[0] + '.mobi'
|
||||||
with tempfile.NamedTemporaryFile('_kindlegen_output.txt') as tfile:
|
with tempfile.NamedTemporaryFile(suffix='_kindlegen_output.txt') as tfile:
|
||||||
p = subprocess.Popen([exe, opf, '-c1', '-verbose', '-o', oname],
|
p = subprocess.Popen([exe, opf, '-c1', '-verbose', '-o', oname],
|
||||||
stderr=subprocess.STDOUT, stdout=tfile)
|
stderr=subprocess.STDOUT, stdout=tfile)
|
||||||
returncode = p.wait()
|
returncode = p.wait()
|
||||||
@ -63,11 +63,7 @@ def kindlegen(oeb, opts, input_plugin, output_path):
|
|||||||
oeb_output = plugin_for_output_format('oeb')
|
oeb_output = plugin_for_output_format('oeb')
|
||||||
oeb_output.convert(oeb, tdir, input_plugin, opts, oeb.log)
|
oeb_output.convert(oeb, tdir, input_plugin, opts, oeb.log)
|
||||||
opf = [x for x in os.listdir(tdir) if x.endswith('.opf')][0]
|
opf = [x for x in os.listdir(tdir) if x.endswith('.opf')][0]
|
||||||
refactor_opf(opf, is_periodical)
|
refactor_opf(os.path.join(tdir, opf), is_periodical, oeb.toc)
|
||||||
with CurrentDir(tdir):
|
|
||||||
oname = run_kindlegen(opf, oeb.log)
|
|
||||||
shutil.copyfile(oname, output_path)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if os.path.exists('/tmp/kindlegen'):
|
if os.path.exists('/tmp/kindlegen'):
|
||||||
shutil.rmtree('/tmp/kindlegen')
|
shutil.rmtree('/tmp/kindlegen')
|
||||||
@ -76,3 +72,8 @@ def kindlegen(oeb, opts, input_plugin, output_path):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
with CurrentDir(tdir):
|
||||||
|
oname = run_kindlegen(opf, oeb.log)
|
||||||
|
shutil.copyfile(oname, output_path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,12 +50,14 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
||||||
'book instead of the end. Not recommended.')
|
'book instead of the end. Not recommended.')
|
||||||
),
|
),
|
||||||
|
'''
|
||||||
OptionRecommendation(name='kindlegen',
|
OptionRecommendation(name='kindlegen',
|
||||||
recommended_value=False,
|
recommended_value=False,
|
||||||
help=_('Use kindlegen (must be in your PATH) to generate the'
|
help=('Use kindlegen (must be in your PATH) to generate the'
|
||||||
' binary wrapper for the MOBI format. Useful to debug '
|
' binary wrapper for the MOBI format. Useful to debug '
|
||||||
' the calibre MOBI output.')
|
' the calibre MOBI output.')
|
||||||
),
|
),
|
||||||
|
'''
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user