From f7c2dc9d30ff8cfb6a39cda9e3f1b02e5755e87a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 5 Aug 2018 10:25:37 +0200 Subject: [PATCH] Add support for editing messages with Audio --- .../methods/messages/edit_message_media.py | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index 2ca9ab9f..c6b2eb97 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -25,7 +25,7 @@ from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client.ext import BaseClient, utils from pyrogram.client.types import ( - InputMediaPhoto, InputMediaVideo + InputMediaPhoto, InputMediaVideo, InputMediaAudio ) @@ -136,6 +136,59 @@ class EditMessageMedia(BaseClient): ) ) + if isinstance(media, InputMediaAudio): + if os.path.exists(media.media): + media = self.send( + functions.messages.UploadMedia( + peer=self.resolve_peer(chat_id), + media=types.InputMediaUploadedDocument( + mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "audio/mpeg"), + file=self.save_file(media.media), + attributes=[ + types.DocumentAttributeAudio( + duration=media.duration, + performer=media.performer, + title=media.title + ), + types.DocumentAttributeFilename(os.path.basename(media.media)) + ] + ) + ) + ) + + media = types.InputMediaDocument( + id=types.InputDocument( + id=media.document.id, + access_hash=media.document.access_hash + ) + ) + elif media.media.startswith("http"): + media = types.InputMediaDocumentExternal( + url=media.media + ) + else: + try: + decoded = utils.decode(media.media) + fmt = " 24 else "