diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index 27263a2690..f0af2d28c5 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -198,11 +198,13 @@ class EPUBInput(InputFormatPlugin): ('application/vnd.adobe-page-template+xml','application/text'): not_for_spine.add(id_) + seen = set() for x in list(opf.iterspine()): ref = x.get('idref', None) - if ref is None or ref in not_for_spine: + if not ref or ref in not_for_spine or ref in seen: x.getparent().remove(x) continue + seen.add(ref) if len(list(opf.iterspine())) == 0: raise ValueError('No valid entries in the spine of this EPUB') diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index debd69b281..d132fe15d0 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -286,15 +286,17 @@ class Spine(ResourceCollection): # {{{ @staticmethod def from_opf_spine_element(itemrefs, manifest): s = Spine(manifest) + seen = set() for itemref in itemrefs: idref = itemref.get('idref', None) if idref is not None: path = s.manifest.path_for_id(idref) - if path: + if path and path not in seen: r = Spine.Item(lambda x:idref, path, is_path=True) r.is_linear = itemref.get('linear', 'yes') == 'yes' r.idref = idref s.append(r) + seen.add(path) return s @staticmethod diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index 2b3cfd7a4a..db0276b8ee 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -221,7 +221,7 @@ class PDFWriter(QObject): # {{{ self.tmp_path = PersistentTemporaryDirectory('_pdf_output_parts') def insert_cover(self): - if self.cover_data is None: + if not isinstance(self.cover_data, bytes): return item_path = os.path.join(self.tmp_path, 'cover.pdf') printer = get_pdf_printer(self.opts, output_file_name=item_path,