From d8a760e9a86342786e0f1d6280c0a5e597fd3b55 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sun, 24 Dec 2023 10:14:02 +0300 Subject: [PATCH] Fix message.download in case of Story --- pyrogram/methods/messages/download_media.py | 9 ++- pyrogram/types/messages_and_media/story.py | 77 +-------------------- 2 files changed, 9 insertions(+), 77 deletions(-) diff --git a/pyrogram/methods/messages/download_media.py b/pyrogram/methods/messages/download_media.py index 4f44ff25..638a1155 100644 --- a/pyrogram/methods/messages/download_media.py +++ b/pyrogram/methods/messages/download_media.py @@ -120,12 +120,19 @@ class DownloadMedia: file_bytes = bytes(file.getbuffer()) """ available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note", - "new_chat_photo") + "new_chat_photo", "story") if isinstance(message, types.Message): for kind in available_media: media = getattr(message, kind, None) + if kind == "story": + for kind in available_media: + media = getattr(message.story, kind, None) + + if media is not None: + break + if media is not None: break else: diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index bea6748e..370981ab 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -63,7 +63,7 @@ class Story(Object, Update): media (:obj:`~pyrogram.enums.MessageMediaType`, *optional*): The media type of the Story. This field will contain the enumeration type of the media message. - You can use ``media = getattr(message, message.media.value)`` to access the media message. + You can use ``media = getattr(message, message.story.media.value)`` to access the media message. has_protected_content (``bool``, *optional*): True, if the story can't be forwarded. @@ -1733,81 +1733,6 @@ class Story(Object, Update): schedule_date=schedule_date ) - async def download( - self, - file_name: str = "", - in_memory: bool = False, - block: bool = True, - progress: Callable = None, - progress_args: tuple = () - ) -> str: - """Bound method *download* of :obj:`~pyrogram.types.Story`. - - Use as a shortcut for: - - .. code-block:: python - - await client.download_media(story) - - Example: - .. code-block:: python - - await story.download() - - Parameters: - file_name (``str``, *optional*): - A custom *file_name* to be used instead of the one provided by Telegram. - By default, all files are downloaded in the *downloads* folder in your working directory. - You can also specify a path for downloading files in a custom location: paths that end with "/" - are considered directories. All non-existent folders will be created automatically. - - in_memory (``bool``, *optional*): - Pass True to download the media in-memory. - A binary file-like object with its attribute ".name" set will be returned. - Defaults to False. - - block (``bool``, *optional*): - Blocks the code execution until the file has been downloaded. - Defaults to True. - - progress (``Callable``, *optional*): - Pass a callback function to view the file transmission progress. - The function must take *(current, total)* as positional arguments (look at Other Parameters below for a - detailed description) and will be called back each time a new file chunk has been successfully - transmitted. - - progress_args (``tuple``, *optional*): - Extra custom arguments for the progress callback function. - You can pass anything you need to be available in the progress callback scope; for example, a Message - object or a Client instance in order to edit the message with the updated progress status. - - Other Parameters: - current (``int``): - The amount of bytes transmitted so far. - - total (``int``): - The total size of the file. - - *args (``tuple``, *optional*): - Extra custom arguments as defined in the ``progress_args`` parameter. - You can either keep ``*args`` or add every single extra argument in your function signature. - - Returns: - On success, the absolute path of the downloaded file as string is returned, None otherwise. - - Raises: - RPCError: In case of a Telegram RPC error. - ``ValueError``: If the message doesn't contain any downloadable media - """ - return await self._client.download_media( - message=getattr(self, self.media.value), - file_name=file_name, - in_memory=in_memory, - block=block, - progress=progress, - progress_args=progress_args, - ) - async def read(self) -> List[int]: """Bound method *read* of :obj:`~pyrogram.types.Story`.