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:
Kovid Goyal 2023-10-04 13:30:19 +05:30
parent 7897c92a3a
commit 1daa020a4f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 1 deletions

View File

@ -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)

View File

@ -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)