mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix a regression that broke reading of covers from HTMLZ and TXTZ files. Fixes #2038778 [Book cover is not shown after converting from FB2 to HTMLZ](https://bugs.launchpad.net/calibre/+bug/2038778)
This commit is contained in:
parent
f70c8e3d6b
commit
97825e0467
@ -23,17 +23,22 @@ def get_metadata(stream, extract_cover=True):
|
||||
try:
|
||||
with ZipFile(stream) as zf:
|
||||
opf_name = get_first_opf_name(zf)
|
||||
opf_stream = io.BytesIO(zf.read(opf_name))
|
||||
opf = OPF(opf_stream)
|
||||
with zf.open(opf_name) as opf_stream:
|
||||
opf = OPF(opf_stream)
|
||||
mi = opf.to_book_metadata()
|
||||
if extract_cover:
|
||||
cover_href = opf.raster_cover
|
||||
cover_href = opf.raster_cover or opf.guide_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
|
||||
else:
|
||||
for val in opf.guide_cover_path(opf.root):
|
||||
if val.rpartition('.')[2].lower() in {'jpeg', 'jpg', 'png'}:
|
||||
cover_href = val
|
||||
break
|
||||
if cover_href:
|
||||
try:
|
||||
mi.cover_data = (os.path.splitext(cover_href)[1], zf.read(cover_href))
|
||||
|
Loading…
x
Reference in New Issue
Block a user