From aa37d7963d2d85eb3a61abac955825867cfd1432 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 19 Aug 2011 11:20:20 -0600 Subject: [PATCH] FB2 Input: When convert FB2 files, read the cover from the fb2 file correctly. Fixes #829240 (Cover lost when converting fb2 to mobi by command line) --- src/calibre/ebooks/fb2/input.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/fb2/input.py b/src/calibre/ebooks/fb2/input.py index 3d3ec69833..3c62b9671d 100644 --- a/src/calibre/ebooks/fb2/input.py +++ b/src/calibre/ebooks/fb2/input.py @@ -100,23 +100,28 @@ class FB2Input(InputFormatPlugin): mi.title = _('Unknown') if not mi.authors: mi.authors = [_('Unknown')] - opf = OPFCreator(os.getcwdu(), mi) - entries = [(f, guess_type(f)[0]) for f in os.listdir('.')] - opf.create_manifest(entries) - opf.create_spine(['index.xhtml']) + cpath = None if mi.cover_data and mi.cover_data[1]: with open('fb2_cover_calibre_mi.jpg', 'wb') as f: f.write(mi.cover_data[1]) - opf.guide.set_cover(os.path.abspath('fb2_cover_calibre_mi.jpg')) + cpath = os.path.abspath('fb2_cover_calibre_mi.jpg') else: for img in doc.xpath('//f:coverpage/f:image', namespaces=NAMESPACES): 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)) + cpath = os.path.abspath(href) + break - opf.render(open('metadata.opf', 'wb')) + opf = OPFCreator(os.getcwdu(), mi) + entries = [(f, guess_type(f)[0]) for f in os.listdir('.')] + opf.create_manifest(entries) + opf.create_spine(['index.xhtml']) + if cpath: + opf.guide.set_cover(cpath) + with open('metadata.opf', 'wb') as f: + opf.render(f) return os.path.join(os.getcwd(), 'metadata.opf') def extract_embedded_content(self, doc):