From 30de50d4a9a9aec16361e4e9eff4ab928a322dd3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 27 Apr 2013 12:38:14 +0530 Subject: [PATCH] FB2 Output: Fix images being ignored when converting a EPUB with image filenames that contain URL unsafe characters. Fixes #1173351 (epub to fb2 converter doesn't keep pictures but the frontpage.) --- src/calibre/ebooks/fb2/fb2ml.py | 14 +++++++++----- src/calibre/gui2/metadata/diff.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/calibre/gui2/metadata/diff.py diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 74a97bf727..35ebb601fd 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -19,6 +19,7 @@ from calibre import prepare_string_for_xml from calibre.constants import __appname__, __version__ from calibre.utils.magick import Image from calibre.utils.localization import lang_as_iso639_1 +from calibre.ebooks.oeb.base import urlnormalize class FB2MLizer(object): ''' @@ -281,7 +282,7 @@ class FB2MLizer(object): data += char images.append('%s\n' % (self.image_hrefs[item.href], data)) except Exception as e: - self.log.error('Error: Could not include file %s because ' \ + self.log.error('Error: Could not include file %s because ' '%s.' % (item.href, e)) return ''.join(images) @@ -420,13 +421,16 @@ class FB2MLizer(object): if tag == 'img': if elem_tree.attrib.get('src', None): # Only write the image tag if it is in the manifest. - if page.abshref(elem_tree.attrib['src']) in self.oeb_book.manifest.hrefs.keys(): - if page.abshref(elem_tree.attrib['src']) not in self.image_hrefs.keys(): - self.image_hrefs[page.abshref(elem_tree.attrib['src'])] = '_%s.jpg' % len(self.image_hrefs.keys()) + ihref = urlnormalize(page.abshref(elem_tree.attrib['src'])) + if ihref in self.oeb_book.manifest.hrefs: + if ihref not in self.image_hrefs: + self.image_hrefs[ihref] = '_%s.jpg' % len(self.image_hrefs) p_txt, p_tag = self.ensure_p() fb2_out += p_txt tags += p_tag - fb2_out.append('' % self.image_hrefs[page.abshref(elem_tree.attrib['src'])]) + fb2_out.append('' % self.image_hrefs[ihref]) + else: + self.log.warn(u'Ignoring image not in manifest: %s'%ihref) if tag in ('br', 'hr') or ems >= 1: if ems < 1: multiplier = 1 diff --git a/src/calibre/gui2/metadata/diff.py b/src/calibre/gui2/metadata/diff.py new file mode 100644 index 0000000000..2dfbaa2fb8 --- /dev/null +++ b/src/calibre/gui2/metadata/diff.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2013, Kovid Goyal ' + + +