Fix Telegram only recognises 3 image filetypes

This commit is contained in:
Lonami Exo 2018-03-15 09:52:45 +01:00
parent 423f0f366c
commit 45b7318f08

View File

@ -4,10 +4,11 @@ to convert between an entity like an User, Chat, etc. into its Input version)
""" """
import math import math
import mimetypes import mimetypes
import os
import re import re
import types import types
from collections import UserList from collections import UserList
from mimetypes import add_type, guess_extension from mimetypes import guess_extension
from .tl.types import ( from .tl.types import (
Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull, Channel, ChannelForbidden, Chat, ChatEmpty, ChatForbidden, ChatFull,
@ -315,11 +316,13 @@ def get_input_media(media, is_photo=False):
def is_image(file): 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): if not isinstance(file, str):
return False return False
mime = mimetypes.guess_type(file)[0] or '' _, ext = os.path.splitext(file)
return mime.startswith('image/') and not mime.endswith('/webp') return re.match(r'\.(png|jpe?g|gif)', ext, re.IGNORECASE)
def is_audio(file): def is_audio(file):