Do not error out when removing old cover if there are images with invalid URLs in the HTML

This commit is contained in:
Kovid Goyal 2016-10-13 06:08:29 +05:30
parent 42b0acbfa3
commit e1c0cbf9e4

View File

@ -171,11 +171,14 @@ class MergeMetadata(object):
for item in self.oeb.spine:
try:
images = XPath('//h:img[@src]')(item.data)
except:
images = []
except Exception:
images = ()
removed = False
for img in images:
try:
href = item.abshref(img.get('src'))
except Exception:
continue # Invalid URL, ignore
if href == cover_item.href:
img.getparent().remove(img)
removed = True
@ -195,6 +198,3 @@ class MergeMetadata(object):
' the cover image'%item.href)
self.oeb.spine.remove(item)
self.oeb.manifest.remove(item)