When polishing cover ensure it has id='cover'

This commit is contained in:
Kovid Goyal 2013-02-13 10:27:45 +05:30
parent 6aaee7085a
commit 4ad4d11535
2 changed files with 13 additions and 2 deletions

View File

@ -82,8 +82,8 @@ class OEBOutput(OutputFormatPlugin):
self.log.warn('The cover image has an id != "cover". Renaming' self.log.warn('The cover image has an id != "cover". Renaming'
' to work around bug in Nook Color') ' to work around bug in Nook Color')
import uuid from calibre.ebooks.oeb.base import uuid_id
newid = str(uuid.uuid4()) newid = uuid_id()
for item in manifest_items_with_id('cover'): for item in manifest_items_with_id('cover'):
item.set('id', newid) item.set('id', newid)

View File

@ -157,6 +157,17 @@ def create_epub_cover(container, cover_path):
with container.open(titlepage, 'wb') as f: with container.open(titlepage, 'wb') as f:
f.write(raw) 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] spine = container.opf_xpath('//opf:spine')[0]
ref = spine.makeelement(OPF('itemref'), idref=titlepage_item.get('id')) ref = spine.makeelement(OPF('itemref'), idref=titlepage_item.get('id'))
container.insert_into_xml(spine, ref, index=0) container.insert_into_xml(spine, ref, index=0)