mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Add support for animations in edit_message_media
This commit is contained in:
parent
4fe9cffc32
commit
ec0d6dd6e0
@ -25,7 +25,8 @@ 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, InputMediaAudio
|
||||
InputMediaPhoto, InputMediaVideo, InputMediaAudio,
|
||||
InputMediaAnimation
|
||||
)
|
||||
|
||||
|
||||
@ -189,6 +190,61 @@ class EditMessageMedia(BaseClient):
|
||||
)
|
||||
)
|
||||
|
||||
if isinstance(media, InputMediaAnimation):
|
||||
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[".mp4"],
|
||||
file=self.save_file(media.media),
|
||||
attributes=[
|
||||
types.DocumentAttributeVideo(
|
||||
supports_streaming=True,
|
||||
duration=media.duration,
|
||||
w=media.width,
|
||||
h=media.height
|
||||
),
|
||||
types.DocumentAttributeFilename(os.path.basename(media.media)),
|
||||
types.DocumentAttributeAnimated()
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
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 = "<iiqqqqi" if len(decoded) > 24 else "<iiqq"
|
||||
unpacked = struct.unpack(fmt, decoded)
|
||||
except (AssertionError, binascii.Error, struct.error):
|
||||
raise FileIdInvalid from None
|
||||
else:
|
||||
if unpacked[0] != 10:
|
||||
media_type = BaseClient.MEDIA_TYPE_ID.get(unpacked[0], None)
|
||||
|
||||
if media_type:
|
||||
raise FileIdInvalid("The file_id belongs to a {}".format(media_type))
|
||||
else:
|
||||
raise FileIdInvalid("Unknown media type: {}".format(unpacked[0]))
|
||||
|
||||
media = types.InputMediaDocument(
|
||||
id=types.InputDocument(
|
||||
id=unpacked[2],
|
||||
access_hash=unpacked[3]
|
||||
)
|
||||
)
|
||||
|
||||
r = self.send(
|
||||
functions.messages.EditMessage(
|
||||
peer=self.resolve_peer(chat_id),
|
||||
|
Loading…
x
Reference in New Issue
Block a user