From 8f3de80064c399d745cf0468827e9a482abddbb2 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Tue, 8 Sep 2020 00:39:42 +0430 Subject: [PATCH] switched to returning None for non-seekable files --- telethon/utils.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/telethon/utils.py b/telethon/utils.py index fbcbb450..86a8661e 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -611,6 +611,7 @@ def _get_metadata(file): # The parser may fail and we don't want to crash if # the extraction process fails. try: + # Note: aiofiles are intentionally left out for simplicity if isinstance(file, str): stream = open(file, 'rb') elif isinstance(file, bytes): @@ -624,22 +625,18 @@ def _get_metadata(file): seekable = False if not seekable: - _log.warning( - '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 + return None pos = stream.tell() filename = getattr(file, 'name', '') + parser = hachoir.parser.guess.guessParser(hachoir.stream.InputIOStream( stream, source='file:' + filename, tags=[], filename=filename )) + return hachoir.metadata.extractMetadata(parser) except Exception as e: