mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix incorrect cover for AZW3 version of calibre User Manual. Fixes #2037898 [Incorrect cover for an .azw3 book](https://bugs.launchpad.net/calibre/+bug/2037898)
This commit is contained in:
parent
7897c92a3a
commit
1daa020a4f
@ -105,4 +105,3 @@ def rebuild(src_dir, dest_path):
|
||||
# do_rebuild(*args)
|
||||
fork_job('calibre.ebooks.mobi.tweak', 'do_rebuild', args=(opf, dest_path),
|
||||
no_output=True)
|
||||
|
||||
|
@ -1472,6 +1472,26 @@ def opf_to_azw3(opf, outpath, container):
|
||||
|
||||
def epub_to_azw3(epub, outpath=None):
|
||||
container = get_container(epub, tweak_mode=True)
|
||||
changed = False
|
||||
for item in container.opf_xpath('//opf:manifest/opf:item[@properties and @href]'):
|
||||
p = item.get('properties').split()
|
||||
if 'cover-image' in p:
|
||||
href = item.get('href')
|
||||
guides = container.opf_xpath('//opf:guide')
|
||||
if not guides:
|
||||
guides = (container.opf.makeelement(OPF('guide')),)
|
||||
container.opf.append(guides[0])
|
||||
for guide in guides:
|
||||
for child in guide:
|
||||
if child.get('type') == 'cover':
|
||||
break
|
||||
else:
|
||||
guide.append(guide.makeelement(OPF('reference'), type='cover', href=href))
|
||||
changed = True
|
||||
break
|
||||
if changed:
|
||||
container.dirty(container.opf_name)
|
||||
container.commit_item(container.opf_name)
|
||||
outpath = outpath or (epub.rpartition('.')[0] + '.azw3')
|
||||
opf_to_azw3(container.name_to_abspath(container.opf_name), outpath, container)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user