diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index 46a3c11387..553b04ffa6 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -99,7 +99,24 @@ class EPUBInput(InputFormatPlugin): ''' If there is a reference to the cover/titlepage via manifest properties, convert to entries in the so that the rest of the pipeline picks it up. ''' from calibre.ebooks.metadata.opf3 import items_with_property - removed = None + removed = guide_titlepage_href = guide_titlepage_id = None + + # Look for titlepages incorrectly marked in the as covers + guide_cover, guide_elem = None, None + for guide_elem in opf.iterguide(): + if guide_elem.get('type', '').lower() == 'cover': + guide_cover = guide_elem.get('href', '').partition('#')[0] + break + if guide_cover: + spine = list(opf.iterspine()) + if spine: + idref = spine[0].get('idref', '') + for x in opf.itermanifest(): + if x.get('id') == idref and x.get('href') == guide_cover: + guide_titlepage_href = guide_cover + guide_titlepage_id = idref + break + raster_cover_href = opf.epub3_raster_cover if raster_cover_href: self.set_guide_type(opf, 'cover', raster_cover_href, 'Cover Image') @@ -109,6 +126,8 @@ class EPUBInput(InputFormatPlugin): if href and tid: titlepage_id, titlepage_href = tid, href.partition('#')[0] break + if titlepage_href is None: + titlepage_href, titlepage_id = guide_titlepage_href, guide_titlepage_id if titlepage_href is not None: self.set_guide_type(opf, 'titlepage', titlepage_href, 'Title Page') spine = list(opf.iterspine())