mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 03:00:15 +03:00
switched to returning None for non-seekable files
This commit is contained in:
parent
92beac2e35
commit
8f3de80064
|
@ -611,6 +611,7 @@ def _get_metadata(file):
|
||||||
# The parser may fail and we don't want to crash if
|
# The parser may fail and we don't want to crash if
|
||||||
# the extraction process fails.
|
# the extraction process fails.
|
||||||
try:
|
try:
|
||||||
|
# Note: aiofiles are intentionally left out for simplicity
|
||||||
if isinstance(file, str):
|
if isinstance(file, str):
|
||||||
stream = open(file, 'rb')
|
stream = open(file, 'rb')
|
||||||
elif isinstance(file, bytes):
|
elif isinstance(file, bytes):
|
||||||
|
@ -624,22 +625,18 @@ def _get_metadata(file):
|
||||||
seekable = False
|
seekable = False
|
||||||
|
|
||||||
if not seekable:
|
if not seekable:
|
||||||
_log.warning(
|
return None
|
||||||
'Could not read metadata since the file is not '
|
|
||||||
'seekable so the entire file will be read in-memory')
|
|
||||||
|
|
||||||
data = file.read()
|
|
||||||
stream = io.BytesIO(data)
|
|
||||||
close_stream = True
|
|
||||||
|
|
||||||
pos = stream.tell()
|
pos = stream.tell()
|
||||||
filename = getattr(file, 'name', '')
|
filename = getattr(file, 'name', '')
|
||||||
|
|
||||||
parser = hachoir.parser.guess.guessParser(hachoir.stream.InputIOStream(
|
parser = hachoir.parser.guess.guessParser(hachoir.stream.InputIOStream(
|
||||||
stream,
|
stream,
|
||||||
source='file:' + filename,
|
source='file:' + filename,
|
||||||
tags=[],
|
tags=[],
|
||||||
filename=filename
|
filename=filename
|
||||||
))
|
))
|
||||||
|
|
||||||
return hachoir.metadata.extractMetadata(parser)
|
return hachoir.metadata.extractMetadata(parser)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user