mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
EPUB Input: Handle files that have duplicate entries in the spine
This commit is contained in:
parent
46a379116e
commit
5b5bb8caaa
@ -198,11 +198,13 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
('application/vnd.adobe-page-template+xml','application/text'):
|
('application/vnd.adobe-page-template+xml','application/text'):
|
||||||
not_for_spine.add(id_)
|
not_for_spine.add(id_)
|
||||||
|
|
||||||
|
seen = set()
|
||||||
for x in list(opf.iterspine()):
|
for x in list(opf.iterspine()):
|
||||||
ref = x.get('idref', None)
|
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)
|
x.getparent().remove(x)
|
||||||
continue
|
continue
|
||||||
|
seen.add(ref)
|
||||||
|
|
||||||
if len(list(opf.iterspine())) == 0:
|
if len(list(opf.iterspine())) == 0:
|
||||||
raise ValueError('No valid entries in the spine of this EPUB')
|
raise ValueError('No valid entries in the spine of this EPUB')
|
||||||
|
@ -286,15 +286,17 @@ class Spine(ResourceCollection): # {{{
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_opf_spine_element(itemrefs, manifest):
|
def from_opf_spine_element(itemrefs, manifest):
|
||||||
s = Spine(manifest)
|
s = Spine(manifest)
|
||||||
|
seen = set()
|
||||||
for itemref in itemrefs:
|
for itemref in itemrefs:
|
||||||
idref = itemref.get('idref', None)
|
idref = itemref.get('idref', None)
|
||||||
if idref is not None:
|
if idref is not None:
|
||||||
path = s.manifest.path_for_id(idref)
|
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 = Spine.Item(lambda x:idref, path, is_path=True)
|
||||||
r.is_linear = itemref.get('linear', 'yes') == 'yes'
|
r.is_linear = itemref.get('linear', 'yes') == 'yes'
|
||||||
r.idref = idref
|
r.idref = idref
|
||||||
s.append(r)
|
s.append(r)
|
||||||
|
seen.add(path)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -221,7 +221,7 @@ class PDFWriter(QObject): # {{{
|
|||||||
self.tmp_path = PersistentTemporaryDirectory('_pdf_output_parts')
|
self.tmp_path = PersistentTemporaryDirectory('_pdf_output_parts')
|
||||||
|
|
||||||
def insert_cover(self):
|
def insert_cover(self):
|
||||||
if self.cover_data is None:
|
if not isinstance(self.cover_data, bytes):
|
||||||
return
|
return
|
||||||
item_path = os.path.join(self.tmp_path, 'cover.pdf')
|
item_path = os.path.join(self.tmp_path, 'cover.pdf')
|
||||||
printer = get_pdf_printer(self.opts, output_file_name=item_path,
|
printer = get_pdf_printer(self.opts, output_file_name=item_path,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user