EPUB Input: Handle files that have duplicate entries in the spine

This commit is contained in:
Kovid Goyal 2012-07-27 15:42:01 +05:30
parent 46a379116e
commit 5b5bb8caaa
3 changed files with 7 additions and 3 deletions

View File

@ -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')

View File

@ -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

View File

@ -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,