E-book viewer: Display cover when viewing FB2 files

This commit is contained in:
Kovid Goyal 2011-01-16 16:51:26 -07:00
parent 799b0f6033
commit ca0e545253
2 changed files with 12 additions and 8 deletions

View File

@ -104,13 +104,17 @@ class FB2Input(InputFormatPlugin):
entries = [(f, guess_type(f)[0]) for f in os.listdir('.')] entries = [(f, guess_type(f)[0]) for f in os.listdir('.')]
opf.create_manifest(entries) opf.create_manifest(entries)
opf.create_spine(['index.xhtml']) opf.create_spine(['index.xhtml'])
if mi.cover_data and mi.cover_data[1]:
for img in doc.xpath('//f:coverpage/f:image', namespaces=NAMESPACES): with open('fb2_cover_calibre_mi.jpg', 'wb') as f:
href = img.get('{%s}href'%XLINK_NS, img.get('href', None)) f.write(mi.cover_data[1])
if href is not None: opf.guide.set_cover(os.path.abspath('fb2_cover_calibre_mi.jpg'))
if href.startswith('#'): else:
href = href[1:] for img in doc.xpath('//f:coverpage/f:image', namespaces=NAMESPACES):
opf.guide.set_cover(os.path.abspath(href)) href = img.get('{%s}href'%XLINK_NS, img.get('href', None))
if href is not None:
if href.startswith('#'):
href = href[1:]
opf.guide.set_cover(os.path.abspath(href))
opf.render(open('metadata.opf', 'wb')) opf.render(open('metadata.opf', 'wb'))
return os.path.join(os.getcwd(), 'metadata.opf') return os.path.join(os.getcwd(), 'metadata.opf')

View File

@ -227,7 +227,7 @@ class EbookIterator(object):
self.log.warn('Missing spine item:', repr(spath)) self.log.warn('Missing spine item:', repr(spath))
cover = self.opf.cover cover = self.opf.cover
if self.ebook_ext in ('lit', 'mobi', 'prc', 'opf') and cover: if self.ebook_ext in ('lit', 'mobi', 'prc', 'opf', 'fb2') and cover:
cfile = os.path.join(self.base, 'calibre_iterator_cover.html') cfile = os.path.join(self.base, 'calibre_iterator_cover.html')
chtml = (TITLEPAGE%os.path.relpath(cover, self.base).replace(os.sep, chtml = (TITLEPAGE%os.path.relpath(cover, self.base).replace(os.sep,
'/')).encode('utf-8') '/')).encode('utf-8')