mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-18 13:34:54 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/client/methods/messages/edit_message_media.py
This commit is contained in:
commit
b78b72d7dc
@ -26,7 +26,7 @@ from pyrogram.api.errors import FileIdInvalid
|
|||||||
from pyrogram.client.ext import BaseClient, utils
|
from pyrogram.client.ext import BaseClient, utils
|
||||||
from pyrogram.client.types import (
|
from pyrogram.client.types import (
|
||||||
InputMediaPhoto, InputMediaVideo, InputMediaAudio,
|
InputMediaPhoto, InputMediaVideo, InputMediaAudio,
|
||||||
InputMediaAnimation
|
InputMediaAnimation, InputMediaDocument
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -245,6 +245,54 @@ class EditMessageMedia(BaseClient):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if isinstance(media, InputMediaDocument):
|
||||||
|
if os.path.exists(media.media):
|
||||||
|
media = await self.send(
|
||||||
|
functions.messages.UploadMedia(
|
||||||
|
peer=await self.resolve_peer(chat_id),
|
||||||
|
media=types.InputMediaUploadedDocument(
|
||||||
|
mime_type=mimetypes.types_map.get("." + media.media.split(".")[-1], "text/plain"),
|
||||||
|
file=await self.save_file(media.media),
|
||||||
|
attributes=[
|
||||||
|
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 = "<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] not in (5, 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 = await self.send(
|
r = await self.send(
|
||||||
functions.messages.EditMessage(
|
functions.messages.EditMessage(
|
||||||
peer=await self.resolve_peer(chat_id),
|
peer=await self.resolve_peer(chat_id),
|
||||||
|
Loading…
Reference in New Issue
Block a user