From 0917460e68b71f4b08bd45e6487dfad1ec8a4ff0 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Thu, 1 Mar 2012 21:27:48 -0600 Subject: [PATCH] Fix for pre-existing epubs with stripped img tags. --- fanficdownloader/adapters/base_adapter.py | 6 ++++-- fanficdownloader/epubutils.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fanficdownloader/adapters/base_adapter.py b/fanficdownloader/adapters/base_adapter.py index 0d3f7d8..b530daa 100644 --- a/fanficdownloader/adapters/base_adapter.py +++ b/fanficdownloader/adapters/base_adapter.py @@ -284,8 +284,10 @@ class BaseSiteAdapter(Configurable): if self.getConfig('include_images'): acceptable_attributes.extend(('src','alt','longdesc')) for img in soup.findAll('img'): - img['longdesc']=img['src'] - img['src']=self.story.addImgUrl(self,url,img['src'],fetch) + # some pre-existing epubs have img tags that had src stripped off. + if 'src' in img: + img['longdesc']=img['src'] + img['src']=self.story.addImgUrl(self,url,img['src'],fetch) for attr in soup._getAttrMap().keys(): if attr not in acceptable_attributes: diff --git a/fanficdownloader/epubutils.py b/fanficdownloader/epubutils.py index 27d5257..8fcf30f 100644 --- a/fanficdownloader/epubutils.py +++ b/fanficdownloader/epubutils.py @@ -56,6 +56,8 @@ def get_update_data(inputio, if getsoups: soup = bs.BeautifulSoup(epub.read(href).decode("utf-8")) for img in soup.findAll('img'): + newsrc='' + longdesc='' try: newsrc=get_path_part(href)+img['src'] # remove all .. and the path part above it, if present.