mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
EPUB Output: Try to ensure that the cover image always has an id="cover" to workaround Nook cover reading bug. Fixes #8182 (Book cover problem when converting to epub for Nookcolor)
This commit is contained in:
parent
14c64a2e1c
commit
8e0efbbb5f
@ -32,6 +32,12 @@ class OEBOutput(OutputFormatPlugin):
|
|||||||
for key in (OPF_MIME, NCX_MIME, PAGE_MAP_MIME):
|
for key in (OPF_MIME, NCX_MIME, PAGE_MAP_MIME):
|
||||||
href, root = results.pop(key, [None, None])
|
href, root = results.pop(key, [None, None])
|
||||||
if root is not None:
|
if root is not None:
|
||||||
|
if key == OPF_MIME:
|
||||||
|
try:
|
||||||
|
self.workaround_nook_cover_bug(root)
|
||||||
|
except:
|
||||||
|
self.log.exception('Something went wrong while trying to'
|
||||||
|
' workaround Nook cover bug, ignoring')
|
||||||
raw = etree.tostring(root, pretty_print=True,
|
raw = etree.tostring(root, pretty_print=True,
|
||||||
encoding='utf-8', xml_declaration=True)
|
encoding='utf-8', xml_declaration=True)
|
||||||
if key == OPF_MIME:
|
if key == OPF_MIME:
|
||||||
@ -49,3 +55,24 @@ class OEBOutput(OutputFormatPlugin):
|
|||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(str(item))
|
f.write(str(item))
|
||||||
item.unload_data_from_memory(memory=path)
|
item.unload_data_from_memory(memory=path)
|
||||||
|
|
||||||
|
def workaround_nook_cover_bug(self, root): # {{{
|
||||||
|
cov = root.xpath('//*[local-name() = "meta" and @name="cover" and'
|
||||||
|
' @content != "cover"]')
|
||||||
|
if len(cov) == 1:
|
||||||
|
manpath = ('//*[local-name() = "manifest"]/*[local-name() = "item" '
|
||||||
|
' and @id="%s" and @media-type]')
|
||||||
|
cov = cov[0]
|
||||||
|
covid = cov.get('content')
|
||||||
|
manifest_item = root.xpath(manpath%covid)
|
||||||
|
has_cover = root.xpath(manpath%'cover')
|
||||||
|
if len(manifest_item) == 1 and not has_cover and \
|
||||||
|
manifest_item[0].get('media-type',
|
||||||
|
'').startswith('image/'):
|
||||||
|
self.log.warn('The cover image has an id != "cover". Renaming'
|
||||||
|
' to work around Nook Color bug')
|
||||||
|
manifest_item = manifest_item[0]
|
||||||
|
manifest_item.set('id', 'cover')
|
||||||
|
cov.set('content', 'cover')
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user