From 531a8369cd13cea1c1de448b50a661906dd0dabc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 19 Dec 2013 14:32:48 +0530 Subject: [PATCH] Edit book: Fix marking image as cover not working for AZW3 files if the file did not previously have a cover --- src/calibre/ebooks/oeb/polish/cover.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 8c6871de53..77f471338b 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -40,8 +40,14 @@ def get_azw3_raster_cover_name(container): def mark_as_cover_azw3(container, name): href = container.name_to_href(name, container.opf_name) + found = False for item in container.opf_xpath('//opf:guide/opf:reference[@href and contains(@type, "cover")]'): item.set('href', href) + found = True + if not found: + for guide in container.opf_xpath('//opf:guide'): + container.insert_into_xml(guide, guide.makeelement( + OPF('reference'), href=href, type='cover')) container.dirty(container.opf_name) def get_raster_cover_name(container):