Add support for in-memory uploads in send_media_group (#519)
* Add support for in-memory uploads for send_media_group * update input_media_photo docs * update type hints Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
This commit is contained in:
parent
317685cf54
commit
0d12d8c1bb
@ -19,6 +19,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import io
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
from pyrogram import raw
|
from pyrogram import raw
|
||||||
@ -87,7 +88,7 @@ class SendMediaGroup(Scaffold):
|
|||||||
|
|
||||||
for i in media:
|
for i in media:
|
||||||
if isinstance(i, types.InputMediaPhoto):
|
if isinstance(i, types.InputMediaPhoto):
|
||||||
if os.path.isfile(i.media):
|
if os.path.isfile(i.media) or isinstance(i.media, io.IOBase):
|
||||||
media = await self.send(
|
media = await self.send(
|
||||||
raw.functions.messages.UploadMedia(
|
raw.functions.messages.UploadMedia(
|
||||||
peer=await self.resolve_peer(chat_id),
|
peer=await self.resolve_peer(chat_id),
|
||||||
@ -124,7 +125,7 @@ class SendMediaGroup(Scaffold):
|
|||||||
else:
|
else:
|
||||||
media = utils.get_input_media_from_file_id(i.media, FileType.PHOTO)
|
media = utils.get_input_media_from_file_id(i.media, FileType.PHOTO)
|
||||||
elif isinstance(i, types.InputMediaVideo):
|
elif isinstance(i, types.InputMediaVideo):
|
||||||
if os.path.isfile(i.media):
|
if os.path.isfile(i.media) or isinstance(i.media, io.IOBase):
|
||||||
media = await self.send(
|
media = await self.send(
|
||||||
raw.functions.messages.UploadMedia(
|
raw.functions.messages.UploadMedia(
|
||||||
peer=await self.resolve_peer(chat_id),
|
peer=await self.resolve_peer(chat_id),
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import Optional, List
|
from typing import Optional, List, Union, BinaryIO
|
||||||
|
|
||||||
from .input_media import InputMedia
|
from .input_media import InputMedia
|
||||||
from ..messages_and_media import MessageEntity
|
from ..messages_and_media import MessageEntity
|
||||||
@ -27,10 +27,11 @@ class InputMediaPhoto(InputMedia):
|
|||||||
It is intended to be used with :obj:`~pyrogram.Client.send_media_group`.
|
It is intended to be used with :obj:`~pyrogram.Client.send_media_group`.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
media (``str``):
|
media (``str`` | ``BinaryIO``):
|
||||||
Photo to send.
|
Photo to send.
|
||||||
Pass a file_id as string to send a photo that exists on the Telegram servers or
|
Pass a file_id as string to send a photo that exists on the Telegram servers or
|
||||||
pass a file path as string to upload a new photo that exists on your local machine or
|
pass a file path as string to upload a new photo that exists on your local machine or
|
||||||
|
pass a binary file-like object with its attribute “.name” set for in-memory uploads or
|
||||||
pass an HTTP URL as a string for Telegram to get a photo from the Internet.
|
pass an HTTP URL as a string for Telegram to get a photo from the Internet.
|
||||||
|
|
||||||
caption (``str``, *optional*):
|
caption (``str``, *optional*):
|
||||||
@ -50,7 +51,7 @@ class InputMediaPhoto(InputMedia):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
media: str,
|
media: Union[str, BinaryIO],
|
||||||
caption: str = "",
|
caption: str = "",
|
||||||
parse_mode: Optional[str] = object,
|
parse_mode: Optional[str] = object,
|
||||||
caption_entities: List[MessageEntity] = None
|
caption_entities: List[MessageEntity] = None
|
||||||
|
Loading…
Reference in New Issue
Block a user