mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
FB2 Input: Handle embedded images correctly, so that EPUB generated from FB2 works with Adobe Digital Editions. Fixes #6183 (No ePub Images shown on Sony PRS-505)
This commit is contained in:
parent
9dcfb101b9
commit
3e0623ab51
@ -60,6 +60,9 @@ class FB2Input(InputFormatPlugin):
|
|||||||
|
|
||||||
transform = etree.XSLT(styledoc)
|
transform = etree.XSLT(styledoc)
|
||||||
result = transform(doc)
|
result = transform(doc)
|
||||||
|
for img in result.xpath('//img[@src]'):
|
||||||
|
src = img.get('src')
|
||||||
|
img.set('src', self.binary_map.get(src, src))
|
||||||
open('index.xhtml', 'wb').write(transform.tostring(result))
|
open('index.xhtml', 'wb').write(transform.tostring(result))
|
||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
mi = get_metadata(stream, 'fb2')
|
mi = get_metadata(stream, 'fb2')
|
||||||
@ -83,9 +86,15 @@ class FB2Input(InputFormatPlugin):
|
|||||||
return os.path.join(os.getcwd(), 'metadata.opf')
|
return os.path.join(os.getcwd(), 'metadata.opf')
|
||||||
|
|
||||||
def extract_embedded_content(self, doc):
|
def extract_embedded_content(self, doc):
|
||||||
|
self.binary_map = {}
|
||||||
for elem in doc.xpath('./*'):
|
for elem in doc.xpath('./*'):
|
||||||
if 'binary' in elem.tag and elem.attrib.has_key('id'):
|
if 'binary' in elem.tag and elem.attrib.has_key('id'):
|
||||||
|
ct = elem.get('content-type', '')
|
||||||
fname = elem.attrib['id']
|
fname = elem.attrib['id']
|
||||||
|
ext = ct.rpartition('/')[-1].lower()
|
||||||
|
if ext in ('png', 'jpeg', 'jpg'):
|
||||||
|
fname += '.' + ext
|
||||||
|
self.binary_map[elem.get('id')] = fname
|
||||||
data = b64decode(elem.text.strip())
|
data = b64decode(elem.text.strip())
|
||||||
open(fname, 'wb').write(data)
|
open(fname, 'wb').write(data)
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ class Scheduler(QObject):
|
|||||||
self.connect(self.timer, SIGNAL('timeout()'), self.check)
|
self.connect(self.timer, SIGNAL('timeout()'), self.check)
|
||||||
self.oldest = gconf['oldest_news']
|
self.oldest = gconf['oldest_news']
|
||||||
self.oldest_timer.start(int(60 * 60 * 1000))
|
self.oldest_timer.start(int(60 * 60 * 1000))
|
||||||
QTimer.singleShot(10 * 1000, self.oldest_check)
|
QTimer.singleShot(5 * 1000, self.oldest_check)
|
||||||
self.database_changed = self.recipe_model.database_changed
|
self.database_changed = self.recipe_model.database_changed
|
||||||
|
|
||||||
def oldest_check(self):
|
def oldest_check(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user