diff --git a/src/calibre/ebooks/mobi/tweak.py b/src/calibre/ebooks/mobi/tweak.py index 512fae4ea5..b51bd4d08f 100644 --- a/src/calibre/ebooks/mobi/tweak.py +++ b/src/calibre/ebooks/mobi/tweak.py @@ -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) - diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index f8b266388d..b397d14078 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -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)