EPUB3 Input: Fix HTML titlepages that are marked using the deprecated <guide> element not being recognized.

Complements the fix for #1746794
This commit is contained in:
Kovid Goyal 2018-02-07 12:35:06 +05:30
parent dce369148d
commit 136e3fec18
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -99,7 +99,24 @@ class EPUBInput(InputFormatPlugin):
''' If there is a reference to the cover/titlepage via manifest properties, convert to ''' If there is a reference to the cover/titlepage via manifest properties, convert to
entries in the <guide> so that the rest of the pipeline picks it up. ''' entries in the <guide> so that the rest of the pipeline picks it up. '''
from calibre.ebooks.metadata.opf3 import items_with_property 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 <guide> 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 raster_cover_href = opf.epub3_raster_cover
if raster_cover_href: if raster_cover_href:
self.set_guide_type(opf, 'cover', raster_cover_href, 'Cover Image') self.set_guide_type(opf, 'cover', raster_cover_href, 'Cover Image')
@ -109,6 +126,8 @@ class EPUBInput(InputFormatPlugin):
if href and tid: if href and tid:
titlepage_id, titlepage_href = tid, href.partition('#')[0] titlepage_id, titlepage_href = tid, href.partition('#')[0]
break break
if titlepage_href is None:
titlepage_href, titlepage_id = guide_titlepage_href, guide_titlepage_id
if titlepage_href is not None: if titlepage_href is not None:
self.set_guide_type(opf, 'titlepage', titlepage_href, 'Title Page') self.set_guide_type(opf, 'titlepage', titlepage_href, 'Title Page')
spine = list(opf.iterspine()) spine = list(opf.iterspine())