def rationalize_cover3(self, opf, log):
     ''' 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. '''
     from calibre.ebooks.metadata.opf3 import items_with_property
     removed = None
     raster_cover_href = opf.epub3_raster_cover
     if raster_cover_href:
         self.set_guide_type(opf, 'cover', raster_cover_href, 'Cover Image')
     titlepage_id = titlepage_href = None
     for item in items_with_property(opf.root, 'calibre:title-page'):
         tid, href = item.get('id'), item.get('href')
         if href and tid:
             titlepage_id, titlepage_href = tid, href.partition('#')[0]
             break
     if titlepage_href is not None:
         self.set_guide_type(opf, 'titlepage', titlepage_href, 'Title Page')
         spine = list(opf.iterspine())
         if len(spine) > 1:
             for item in spine:
                 if item.get('idref') == titlepage_id:
                     log('Found HTML cover', titlepage_href)
                     if self.for_viewer:
                         item.attrib.pop('linear', None)
                     else:
                         item.getparent().remove(item)
                         removed = titlepage_href
                     return removed
Exemple #2
0
 def rationalize_cover3(self, opf, log):
     ''' 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. '''
     from calibre.ebooks.metadata.opf3 import items_with_property
     removed = None
     raster_cover_href = opf.epub3_raster_cover
     if raster_cover_href:
         self.set_guide_type(opf, 'cover', raster_cover_href, 'Cover Image')
     titlepage_id = titlepage_href = None
     for item in items_with_property(opf.root, 'calibre:title-page'):
         tid, href = item.get('id'), item.get('href')
         if href and tid:
             titlepage_id, titlepage_href = tid, href.partition('#')[0]
             break
     if titlepage_href is not None:
         self.set_guide_type(opf, 'titlepage', titlepage_href, 'Title Page')
         spine = list(opf.iterspine())
         if len(spine) > 1:
             for item in spine:
                 if item.get('idref') == titlepage_id:
                     log('Found HTML cover', titlepage_href)
                     if self.for_viewer:
                         item.attrib.pop('linear', None)
                     else:
                         item.getparent().remove(item)
                         removed = titlepage_href
                     return removed
Exemple #3
0
    def rationalize_cover3(self, opf, log):
        ''' 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. '''
        from calibre.ebooks.metadata.opf3 import items_with_property
        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 or opf.raster_cover
        if raster_cover_href:
            self.set_guide_type(opf, 'cover', raster_cover_href, 'Cover Image')
        titlepage_id = titlepage_href = None
        for item in items_with_property(opf.root, 'calibre:title-page'):
            tid, href = item.get('id'), item.get('href')
            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())
            if len(spine) > 1:
                for item in spine:
                    if item.get('idref') == titlepage_id:
                        log('Found HTML cover', titlepage_href)
                        if self.for_viewer:
                            item.attrib.pop('linear', None)
                        else:
                            item.getparent().remove(item)
                            removed = titlepage_href
                        return removed