From 45b7318f083450d0574f7a123735f7fd20342b25 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 15 Mar 2018 09:52:45 +0100 Subject: [PATCH] Fix Telegram only recognises 3 image filetypes --- telethon/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/telethon/utils.py b/telethon/utils.py index daf8c875..ddc920d3 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -4,10 +4,11 @@ to convert between an entity like an User, Chat, etc. into its Input version) """ import math import mimetypes +import os import re import types from collections import UserList -from mimetypes import add_type, guess_extension +from mimetypes import guess_extension from .tl.types import ( Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull, @@ -315,11 +316,13 @@ def get_input_media(media, is_photo=False): def is_image(file): - """Returns True if the file extension looks like an image file""" + """ + Returns True if the file extension looks like an image file to Telegram. + """ if not isinstance(file, str): return False - mime = mimetypes.guess_type(file)[0] or '' - return mime.startswith('image/') and not mime.endswith('/webp') + _, ext = os.path.splitext(file) + return re.match(r'\.(png|jpe?g|gif)', ext, re.IGNORECASE) def is_audio(file):