From d84a8a721a0eb24b8567e09b309315f7fcf7d586 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Apr 2011 14:49:04 -0600 Subject: [PATCH] EPUB Input: Speed up processing of files with very large manifest/spines --- src/calibre/ebooks/epub/input.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/calibre/ebooks/epub/input.py b/src/calibre/ebooks/epub/input.py index e22ed27371..917c5ad8ae 100644 --- a/src/calibre/ebooks/epub/input.py +++ b/src/calibre/ebooks/epub/input.py @@ -175,18 +175,18 @@ class EPUBInput(InputFormatPlugin): raise ValueError( 'EPUB files with DTBook markup are not supported') + not_for_spine = set() + for y in opf.itermanifest(): + id_ = y.get('id', None) + if id_ and y.get('media-type', None) in \ + ('application/vnd.adobe-page-template+xml',): + not_for_spine.add(id_) + for x in list(opf.iterspine()): ref = x.get('idref', None) - if ref is None: + if ref is None or ref in not_for_spine: x.getparent().remove(x) continue - for y in opf.itermanifest(): - if y.get('id', None) == ref and y.get('media-type', None) in \ - ('application/vnd.adobe-page-template+xml',): - p = x.getparent() - if p is not None: - p.remove(x) - break with open('content.opf', 'wb') as nopf: nopf.write(opf.render())