From 5e5860534b70d0dd8f1d4886464d8155bee4b31a Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 30 Dec 2023 14:00:25 +0300 Subject: [PATCH] Revert changes related to the Story.download --- compiler/docs/compiler.py | 1 + pyrogram/types/messages_and_media/story.py | 77 +++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index b20f6865..56b2fa17 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -674,6 +674,7 @@ def pyrogram_api(): Story.reply_video_note Story.reply_voice Story.delete + Story.download Story.edit_media Story.edit_caption Story.edit_privacy diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index 370981ab..f4bdcaaf 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.story.media.value)`` to access the media message. + You can use ``media = getattr(story, story.media.value)`` to access the media message. has_protected_content (``bool``, *optional*): True, if the story can't be forwarded. @@ -1733,6 +1733,81 @@ 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`.