From 50cff068a071dac4cca352315f1462b229030f9e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 12 Feb 2019 20:29:05 +0100 Subject: [PATCH] Fix send_* methods sending the incorrect Telegram media message type This makes Pyrogram consistent with the official Bot API behaviour. --- pyrogram/client/methods/messages/edit_message_media.py | 9 ++++----- pyrogram/client/methods/messages/send_animation.py | 3 +-- pyrogram/client/methods/messages/send_audio.py | 3 +-- pyrogram/client/methods/messages/send_document.py | 3 +-- pyrogram/client/methods/messages/send_media_group.py | 3 +-- pyrogram/client/methods/messages/send_video.py | 3 +-- pyrogram/client/methods/messages/send_video_note.py | 3 +-- pyrogram/client/methods/messages/send_voice.py | 3 +-- 8 files changed, 11 insertions(+), 19 deletions(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 90ef290b..9ad2f199 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -122,7 +121,7 @@ class EditMessageMedia(BaseClient): functions.messages.UploadMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map[".mp4"], + mime_type="video/mp4", thumb=None if media.thumb is None else self.save_file(media.thumb), file=self.save_file(media.media), attributes=[ @@ -179,7 +178,7 @@ class EditMessageMedia(BaseClient): functions.messages.UploadMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "audio/mpeg"), + mime_type="audio/mpeg", thumb=None if media.thumb is None else self.save_file(media.thumb), file=self.save_file(media.media), attributes=[ @@ -235,7 +234,7 @@ class EditMessageMedia(BaseClient): functions.messages.UploadMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map[".mp4"], + mime_type="video/mp4", thumb=None if media.thumb is None else self.save_file(media.thumb), file=self.save_file(media.media), attributes=[ @@ -293,7 +292,7 @@ class EditMessageMedia(BaseClient): functions.messages.UploadMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "text/plain"), + mime_type="application/zip", thumb=None if media.thumb is None else self.save_file(media.thumb), file=self.save_file(media.media), attributes=[ diff --git a/pyrogram/client/methods/messages/send_animation.py b/pyrogram/client/methods/messages/send_animation.py index 5b27c914..8fc31e08 100644 --- a/pyrogram/client/methods/messages/send_animation.py +++ b/pyrogram/client/methods/messages/send_animation.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -132,7 +131,7 @@ class SendAnimation(BaseClient): thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(animation, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map[".mp4"], + mime_type="video/mp4", file=file, thumb=thumb, attributes=[ diff --git a/pyrogram/client/methods/messages/send_audio.py b/pyrogram/client/methods/messages/send_audio.py index baa31a71..a956ba85 100644 --- a/pyrogram/client/methods/messages/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -134,7 +133,7 @@ class SendAudio(BaseClient): thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(audio, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"), + mime_type="audio/mpeg", file=file, thumb=thumb, attributes=[ diff --git a/pyrogram/client/methods/messages/send_document.py b/pyrogram/client/methods/messages/send_document.py index 3a7e190d..35fe8c0e 100644 --- a/pyrogram/client/methods/messages/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -120,7 +119,7 @@ class SendDocument(BaseClient): thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(document, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"), + mime_type="application/zip", file=file, thumb=thumb, attributes=[ diff --git a/pyrogram/client/methods/messages/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py index 6eb0f415..0df273bc 100644 --- a/pyrogram/client/methods/messages/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -18,7 +18,6 @@ import binascii import logging -import mimetypes import os import struct import time @@ -130,7 +129,7 @@ class SendMediaGroup(BaseClient): media=types.InputMediaUploadedDocument( file=self.save_file(i.media), thumb=None if i.thumb is None else self.save_file(i.thumb), - mime_type=mimetypes.types_map[".mp4"], + mime_type="video/mp4", attributes=[ types.DocumentAttributeVideo( supports_streaming=i.supports_streaming or None, diff --git a/pyrogram/client/methods/messages/send_video.py b/pyrogram/client/methods/messages/send_video.py index 8b769054..b69b2185 100644 --- a/pyrogram/client/methods/messages/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -136,7 +135,7 @@ class SendVideo(BaseClient): thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(video, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map[".mp4"], + mime_type="video/mp4", file=file, thumb=thumb, attributes=[ diff --git a/pyrogram/client/methods/messages/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py index bbd17e98..b35dbea6 100644 --- a/pyrogram/client/methods/messages/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -117,7 +116,7 @@ class SendVideoNote(BaseClient): thumb = None if thumb is None else self.save_file(thumb) file = self.save_file(video_note, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map[".mp4"], + mime_type="video/mp4", file=file, thumb=thumb, attributes=[ diff --git a/pyrogram/client/methods/messages/send_voice.py b/pyrogram/client/methods/messages/send_voice.py index b69d7d3a..33261db6 100644 --- a/pyrogram/client/methods/messages/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -17,7 +17,6 @@ # along with Pyrogram. If not, see . import binascii -import mimetypes import os import struct from typing import Union @@ -116,7 +115,7 @@ class SendVoice(BaseClient): if os.path.exists(voice): file = self.save_file(voice, progress=progress, progress_args=progress_args) media = types.InputMediaUploadedDocument( - mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"), + mime_type="audio/mpeg", file=file, attributes=[ types.DocumentAttributeAudio(