Improve handling of images in mobi2oeb

This commit is contained in:
Kovid Goyal 2008-05-19 12:35:35 -07:00
parent f2db341ac1
commit 221421fe51

View File

@ -270,12 +270,17 @@ class MobiReader(object):
im.convert('RGB').save(open(path, 'wb'), format='JPEG') im.convert('RGB').save(open(path, 'wb'), format='JPEG')
def fix_images(match): def fix_images(match):
one = re.compile(r'src=["\']{0,1}[^\'"]+["\']{0,1}', re.IGNORECASE).sub('', match.group(1)).strip() tag = match.group()
return '<img'+one+' src="images/%s.jpg"'%match.group(2) for pat in (r'\shirecindex=[\'"](\d+)[\'"]', '\srecindex=[\'"](\d+)[\'"]', '\slorecindex=[\'"](\d+)[\'"]'):
pat = re.compile(pat)
m = pat.search(tag)
if m:
return pat.sub(' src="images/%s.jpg"'%m.group(1), tag)
if hasattr(self, 'processed_html'): if hasattr(self, 'processed_html'):
self.processed_html = \ self.processed_html = \
re.compile(r'<img(.+?)recindex=[\'"]{0,1}(\d+)[\'"]{0,1}', re.IGNORECASE|re.DOTALL)\ re.compile(r'<img (.*?)>', re.IGNORECASE|re.DOTALL)\
.sub(fix_images, self.processed_html) .sub(fix_images, self.processed_html)
def get_metadata(stream): def get_metadata(stream):