mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-24 20:46:54 +01:00
EPUB Input: Handle files that have duplicate entries in the spine
This commit is contained in:
parent
46a379116e
commit
5b5bb8caaa
3 changed files with 7 additions and 3 deletions
|
|
@ -198,11 +198,13 @@ def convert(self, stream, options, file_ext, log, accelerators):
|
|||
('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')
|
||||
|
|
|
|||
|
|
@ -286,15 +286,17 @@ def __repr__(self):
|
|||
@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
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ def _delete_tmpdir(self):
|
|||
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue