mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 11:10:18 +03:00
fixed issue where >10MB byte array/stream songs were sent as files
This commit is contained in:
parent
02b8f1d007
commit
6baa44b9c8
|
@ -601,13 +601,12 @@ def get_message_id(message):
|
||||||
|
|
||||||
|
|
||||||
def _get_metadata(file):
|
def _get_metadata(file):
|
||||||
# `hachoir` only deals with paths to in-disk files, while
|
# The parser may fail and we don't want to crash if
|
||||||
# `_get_extension` supports a few other things. The parser
|
|
||||||
# may also fail in any case and we don't want to crash if
|
|
||||||
# the extraction process fails.
|
# the extraction process fails.
|
||||||
if hachoir and isinstance(file, str) and os.path.isfile(file):
|
if hachoir:
|
||||||
try:
|
try:
|
||||||
with hachoir.parser.createParser(file) as parser:
|
file = io.BytesIO(file) if isinstance(file, bytes) else file
|
||||||
|
parser = hachoir.parser.createParser(file)
|
||||||
return hachoir.metadata.extractMetadata(parser)
|
return hachoir.metadata.extractMetadata(parser)
|
||||||
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)
|
||||||
|
@ -803,9 +802,16 @@ def is_gif(file):
|
||||||
|
|
||||||
|
|
||||||
def is_audio(file):
|
def is_audio(file):
|
||||||
"""Returns `True` if the file extension looks like an audio file."""
|
"""Returns `True` if the file has an audio mime type."""
|
||||||
file = 'a' + _get_extension(file)
|
filename = 'a' + _get_extension(file)
|
||||||
return (mimetypes.guess_type(file)[0] or '').startswith('audio/')
|
if filename == 'a':
|
||||||
|
metadata = _get_metadata(file)
|
||||||
|
if metadata and metadata.has('mime_type'):
|
||||||
|
return metadata.get('mime_type').startswith('audio/')
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return (mimetypes.guess_type(filename)[0] or '').startswith('audio/')
|
||||||
|
|
||||||
|
|
||||||
def is_video(file):
|
def is_video(file):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user