mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 03:00:15 +03:00
switched to creating parser's stream manually
This commit is contained in:
parent
e73e5c9efc
commit
f21a76ebce
|
@ -605,15 +605,20 @@ def _get_metadata(file):
|
||||||
# the extraction process fails.
|
# the extraction process fails.
|
||||||
if hachoir:
|
if hachoir:
|
||||||
try:
|
try:
|
||||||
|
original_filetype = type(file)
|
||||||
file = io.BytesIO(file) if isinstance(file, bytes) else file
|
file = io.BytesIO(file) if isinstance(file, bytes) else file
|
||||||
parser = hachoir.parser.createParser(file)
|
file = open(file, 'rb') if isinstance(file, str) else file
|
||||||
if isinstance(file, str):
|
filename = getattr(file, 'name', '')
|
||||||
parser.close()
|
stream = hachoir.stream.InputIOStream(file,
|
||||||
return hachoir.metadata.extractMetadata(parser)
|
source='file:' + filename,
|
||||||
except AssertionError:
|
tags=[],
|
||||||
msg = ('Your version of Hachoir can only open in-disk files.'
|
filename=filename)
|
||||||
'Update it to read byte arrays/streams.')
|
parser = hachoir.parser.guess.guessParser(stream)
|
||||||
_log.warning('Failed to analyze %s: %s', file, msg)
|
metadata = hachoir.metadata.extractMetadata(parser)
|
||||||
|
if original_filetype is str:
|
||||||
|
file.close()
|
||||||
|
return metadata
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_log.warning('Failed to analyze %s: %s %s', file, e.__class__, e)
|
_log.warning('Failed to analyze %s: %s %s', file, e.__class__, e)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user