Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Bounded method for download custom emoji stickers #79

Closed
wants to merge 18 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion pyrogram/types/messages_and_media/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
from typing import List, Dict, Type
from typing import List, Dict, Type,Callable

import pyrogram
from pyrogram import raw, utils
Expand Down Expand Up @@ -210,3 +210,79 @@ async def _parse(
thumbs=types.Thumbnail._parse(client, sticker),
client=client
)


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.Sticker`.

Use as a shortcut for:

.. code-block:: python

await client.download_media(message)

Example:
.. code-block:: python

await message.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=self.file_id,
file_name=file_name,
in_memory=in_memory,
block=block,
progress=progress,
progress_args=progress_args,
)