mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-26 12:54:14 +03:00
Fix attributes not being inferred for open()ed files
This commit is contained in:
parent
f0a26d7c76
commit
638eeb3c82
|
@ -419,14 +419,12 @@ def get_attributes(file, *, attributes=None, mime_type=None,
|
||||||
Get a list of attributes for the given file and
|
Get a list of attributes for the given file and
|
||||||
the mime type as a tuple ([attribute], mime_type).
|
the mime type as a tuple ([attribute], mime_type).
|
||||||
"""
|
"""
|
||||||
if isinstance(file, str):
|
name = file if isinstance(file, str) else getattr(file, 'name', 'unnamed')
|
||||||
# Determine mime-type and attributes
|
|
||||||
# Take the first element by using [0] since it returns a tuple
|
|
||||||
if mime_type is None:
|
if mime_type is None:
|
||||||
mime_type = mimetypes.guess_type(file)[0]
|
mime_type = mimetypes.guess_type(name)[0]
|
||||||
|
|
||||||
attr_dict = {types.DocumentAttributeFilename:
|
attr_dict = {types.DocumentAttributeFilename:
|
||||||
types.DocumentAttributeFilename(os.path.basename(file))}
|
types.DocumentAttributeFilename(os.path.basename(name))}
|
||||||
|
|
||||||
if is_audio(file) and hachoir is not None:
|
if is_audio(file) and hachoir is not None:
|
||||||
with hachoir.parser.createParser(file) as parser:
|
with hachoir.parser.createParser(file) as parser:
|
||||||
|
@ -456,10 +454,6 @@ def get_attributes(file, *, attributes=None, mime_type=None,
|
||||||
0, 1, 1, round_message=video_note)
|
0, 1, 1, round_message=video_note)
|
||||||
|
|
||||||
attr_dict[types.DocumentAttributeVideo] = doc
|
attr_dict[types.DocumentAttributeVideo] = doc
|
||||||
else:
|
|
||||||
attr_dict = {types.DocumentAttributeFilename:
|
|
||||||
types.DocumentAttributeFilename(
|
|
||||||
os.path.basename(getattr(file, 'name', None) or 'unnamed'))}
|
|
||||||
|
|
||||||
if voice_note:
|
if voice_note:
|
||||||
if types.DocumentAttributeAudio in attr_dict:
|
if types.DocumentAttributeAudio in attr_dict:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user