From e70550dc8a40254f3ee8103456fec6f6ad2516bf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 Mar 2011 13:23:42 -0600 Subject: [PATCH] Fix #9445 (PocketBook can't always find epub cover image to create thumbnail) --- src/calibre/ebooks/oeb/output.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/calibre/ebooks/oeb/output.py b/src/calibre/ebooks/oeb/output.py index fac6675904..816fe71abb 100644 --- a/src/calibre/ebooks/oeb/output.py +++ b/src/calibre/ebooks/oeb/output.py @@ -38,6 +38,11 @@ class OEBOutput(OutputFormatPlugin): except: self.log.exception('Something went wrong while trying to' ' workaround Nook cover bug, ignoring') + try: + self.workaround_pocketbook_cover_bug(root) + except: + self.log.exception('Something went wrong while trying to' + ' workaround Pocketbook cover bug, ignoring') raw = etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True) if key == OPF_MIME: @@ -90,3 +95,12 @@ class OEBOutput(OutputFormatPlugin): cov.set('content', 'cover') # }}} + def workaround_pocketbook_cover_bug(self, root): # {{{ + m = root.xpath('//*[local-name() = "manifest"]/*[local-name() = "item" ' + ' and @id="cover"]') + if len(m) == 1: + m = m[0] + p = m.getparent() + p.remove(m) + p.insert(0, m) + # }}}