mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Use local open when reading metadata
This commit is contained in:
parent
353624aca3
commit
f069483a3e
@ -48,7 +48,7 @@ def _metadata_from_formats(formats, force_read_metadata=False, pattern=None):
|
||||
return mi2
|
||||
|
||||
for path, ext in zip(formats, extensions):
|
||||
with open(path, 'rb') as stream:
|
||||
with lopen(path, 'rb') as stream:
|
||||
try:
|
||||
newmi = get_metadata(stream, stream_type=ext,
|
||||
use_libprs_metadata=True,
|
||||
@ -218,20 +218,20 @@ def opf_metadata(opfpath):
|
||||
|
||||
def forked_read_metadata(path, tdir):
|
||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||
with open(path, 'rb') as f:
|
||||
with lopen(path, 'rb') as f:
|
||||
fmt = os.path.splitext(path)[1][1:].lower()
|
||||
f.seek(0, 2)
|
||||
sz = f.tell()
|
||||
with open(os.path.join(tdir, 'size.txt'), 'wb') as s:
|
||||
with lopen(os.path.join(tdir, 'size.txt'), 'wb') as s:
|
||||
s.write(str(sz).encode('ascii'))
|
||||
f.seek(0)
|
||||
mi = get_metadata(f, fmt)
|
||||
if mi.cover_data and mi.cover_data[1]:
|
||||
with open(os.path.join(tdir, 'cover.jpg'), 'wb') as f:
|
||||
with lopen(os.path.join(tdir, 'cover.jpg'), 'wb') as f:
|
||||
f.write(mi.cover_data[1])
|
||||
mi.cover_data = (None, None)
|
||||
mi.cover = 'cover.jpg'
|
||||
opf = metadata_to_opf(mi, default_lang='und')
|
||||
with open(os.path.join(tdir, 'metadata.opf'), 'wb') as f:
|
||||
with lopen(os.path.join(tdir, 'metadata.opf'), 'wb') as f:
|
||||
f.write(opf)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user