Fix covers not being read from some TXTZ files. Fixes #1475984 [could not read cover from txtz format](https://bugs.launchpad.net/calibre/+bug/1475984)

This commit is contained in:
Kovid Goyal 2015-07-20 12:01:10 +05:30
parent 336f803883
commit 49a66615e8

View File

@ -22,7 +22,6 @@ def get_metadata(stream, extract_cover=True):
''' '''
mi = MetaInformation(_('Unknown'), [_('Unknown')]) mi = MetaInformation(_('Unknown'), [_('Unknown')])
stream.seek(0) stream.seek(0)
try: try:
with ZipFile(stream) as zf: with ZipFile(stream) as zf:
opf_name = get_first_opf_name(zf) opf_name = get_first_opf_name(zf)
@ -31,9 +30,18 @@ def get_metadata(stream, extract_cover=True):
mi = opf.to_book_metadata() mi = opf.to_book_metadata()
if extract_cover: if extract_cover:
cover_href = opf.raster_cover cover_href = opf.raster_cover
if not cover_href:
for meta in opf.metadata.xpath('//*[local-name()="meta" and @name="cover"]'):
val = meta.get('content')
if val.rpartition('.')[2].lower() in {'jpeg', 'jpg', 'png'}:
cover_href = val
break
if cover_href: if cover_href:
mi.cover_data = (os.path.splitext(cover_href)[1], zf.read(cover_href)) try:
except: mi.cover_data = (os.path.splitext(cover_href)[1], zf.read(cover_href))
except Exception:
pass
except Exception:
return mi return mi
return mi return mi