py3: Fix extracting raster cover from titlepage

Fixes #1012 (py3: fix 'in' operation)
This commit is contained in:
Kovid Goyal 2019-06-25 13:45:26 +05:30
parent 1b6b234c59
commit f663fff3ad
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -10,6 +10,7 @@ from various formats.
import traceback, os, re, numbers
from calibre import CurrentDir, prints
from calibre.ebooks.chardet import xml_to_unicode
from polyglot.builtins import unicode_type
@ -127,18 +128,20 @@ def extract_calibre_cover(raw, base, log):
def render_html_svg_workaround(path_to_html, log, width=590, height=750):
from calibre.ebooks.oeb.base import SVG_NS
raw = open(path_to_html, 'rb').read()
with open(path_to_html, 'rb') as f:
raw = f.read()
raw = xml_to_unicode(raw, strip_encoding_pats=True)[0]
data = None
if SVG_NS in raw:
try:
data = extract_cover_from_embedded_svg(raw,
os.path.dirname(path_to_html), log)
except:
except Exception:
pass
if data is None:
try:
data = extract_calibre_cover(raw, os.path.dirname(path_to_html), log)
except:
except Exception:
pass
if data is None: