Fix attributes not being inferred for open()ed files

This commit is contained in:
Lonami Exo 2018-07-31 12:14:13 +02:00
parent f0a26d7c76
commit 638eeb3c82

View File

@ -419,14 +419,12 @@ def get_attributes(file, *, attributes=None, mime_type=None,
Get a list of attributes for the given file and
the mime type as a tuple ([attribute], mime_type).
"""
if isinstance(file, str):
# Determine mime-type and attributes
# Take the first element by using [0] since it returns a tuple
name = file if isinstance(file, str) else getattr(file, 'name', 'unnamed')
if mime_type is None:
mime_type = mimetypes.guess_type(file)[0]
mime_type = mimetypes.guess_type(name)[0]
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:
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)
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 types.DocumentAttributeAudio in attr_dict: