From 4ad4d1153536fd52c86d370ada04c8db9686d4bc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Feb 2013 10:27:45 +0530 Subject: [PATCH] When polishing cover ensure it has id='cover' --- src/calibre/ebooks/conversion/plugins/oeb_output.py | 4 ++-- src/calibre/ebooks/oeb/polish/cover.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/oeb_output.py b/src/calibre/ebooks/conversion/plugins/oeb_output.py index b69e095d0f..86d3b76a8c 100644 --- a/src/calibre/ebooks/conversion/plugins/oeb_output.py +++ b/src/calibre/ebooks/conversion/plugins/oeb_output.py @@ -82,8 +82,8 @@ class OEBOutput(OutputFormatPlugin): self.log.warn('The cover image has an id != "cover". Renaming' ' to work around bug in Nook Color') - import uuid - newid = str(uuid.uuid4()) + from calibre.ebooks.oeb.base import uuid_id + newid = uuid_id() for item in manifest_items_with_id('cover'): item.set('id', newid) diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 7dd4ba39fe..6eafe5d9dd 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -157,6 +157,17 @@ def create_epub_cover(container, cover_path): with container.open(titlepage, 'wb') as f: f.write(raw) + # We have to make sure the raster cover item has id="cover" for the moron + # that wrote the Nook firmware + if raster_cover_item.get('id') != 'cover': + from calibre.ebooks.oeb.base import uuid_id + newid = uuid_id() + for item in container.opf_xpath('//*[@id="cover"]'): + item.set('id', newid) + for item in container.opf_xpath('//*[@idref="cover"]'): + item.set('idref', newid) + raster_cover_item.set('id', 'cover') + spine = container.opf_xpath('//opf:spine')[0] ref = spine.makeelement(OPF('itemref'), idref=titlepage_item.get('id')) container.insert_into_xml(spine, ref, index=0)