2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Add progress_args parameter

This commit is contained in:
Dan 2018-04-30 19:09:57 +02:00
parent e6b4f0e743
commit a7650c457d

View File

@ -1257,7 +1257,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send photos. """Use this method to send photos.
Args: Args:
@ -1299,15 +1300,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -1318,7 +1331,7 @@ class Client:
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(photo): if os.path.exists(photo):
file = self.save_file(photo, progress=progress) file = self.save_file(photo, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedPhoto( media = types.InputMediaUploadedPhoto(
file=file, file=file,
ttl_seconds=ttl_seconds ttl_seconds=ttl_seconds
@ -1386,7 +1399,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send audio files. """Use this method to send audio files.
For sending voice messages, use the :obj:`send_voice` method instead. For sending voice messages, use the :obj:`send_voice` method instead.
@ -1434,15 +1448,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -1453,7 +1479,7 @@ class Client:
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(audio): if os.path.exists(audio):
file = self.save_file(audio, progress=progress) file = self.save_file(audio, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"), mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"),
file=file, file=file,
@ -1524,7 +1550,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send general files. """Use this method to send general files.
Args: Args:
@ -1561,15 +1588,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -1580,7 +1619,7 @@ class Client:
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(document): if os.path.exists(document):
file = self.save_file(document, progress=progress) file = self.save_file(document, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"), mime_type=mimetypes.types_map.get("." + document.split(".")[-1], "text/plain"),
file=file, file=file,
@ -1644,7 +1683,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send .webp stickers. """Use this method to send .webp stickers.
Args: Args:
@ -1673,15 +1713,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -1691,7 +1743,7 @@ class Client:
file = None file = None
if os.path.exists(sticker): if os.path.exists(sticker):
file = self.save_file(sticker, progress=progress) file = self.save_file(sticker, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type="image/webp", mime_type="image/webp",
file=file, file=file,
@ -1762,7 +1814,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send video files. """Use this method to send video files.
Args: Args:
@ -1816,15 +1869,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -1836,7 +1901,7 @@ class Client:
if os.path.exists(video): if os.path.exists(video):
thumb = None if thumb is None else self.save_file(thumb) thumb = None if thumb is None else self.save_file(thumb)
file = self.save_file(video, progress=progress) file = self.save_file(video, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map[".mp4"], mime_type=mimetypes.types_map[".mp4"],
file=file, file=file,
@ -1910,7 +1975,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send audio files. """Use this method to send audio files.
Args: Args:
@ -1950,15 +2016,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -1969,7 +2047,7 @@ class Client:
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
if os.path.exists(voice): if os.path.exists(voice):
file = self.save_file(voice, progress=progress) file = self.save_file(voice, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"), mime_type=mimetypes.types_map.get("." + voice.split(".")[-1], "audio/mpeg"),
file=file, file=file,
@ -2038,7 +2116,8 @@ class Client:
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None, reply_to_message_id: int = None,
reply_markup=None, reply_markup=None,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send video messages. """Use this method to send video messages.
Args: Args:
@ -2073,15 +2152,27 @@ class Client:
progress (``callable``): progress (``callable``):
Pass a callback function to view the upload progress. Pass a callback function to view the upload progress.
The function must accept two arguments (current, total). The function must take *(client, current, total, \*args)* as positional arguments (look at the section
below for a detailed description).
progress_args (``tuple``):
Extra custom arguments for the progress callback function. Useful, for example, if you want to pass
a chat_id and a message_id in order to edit a message with the updated progress.
Other Parameters: Other Parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the callback function.
current (``int``): current (``int``):
The amount of bytes uploaded so far. The amount of bytes uploaded so far.
total (``int``): total (``int``):
The size of the file. The size of the file.
*args (``tuple``):
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: Returns:
On success, the sent :obj:`Message <pyrogram.Message>` is returned. On success, the sent :obj:`Message <pyrogram.Message>` is returned.
@ -2091,7 +2182,7 @@ class Client:
file = None file = None
if os.path.exists(video_note): if os.path.exists(video_note):
file = self.save_file(video_note, progress=progress) file = self.save_file(video_note, progress=progress, progress_args=progress_args)
media = types.InputMediaUploadedDocument( media = types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map[".mp4"], mime_type=mimetypes.types_map[".mp4"],
file=file, file=file,
@ -2787,7 +2878,8 @@ class Client:
path: str, path: str,
file_id: int = None, file_id: int = None,
file_part: int = 0, file_part: int = 0,
progress: callable = None): progress: callable = None,
progress_args: tuple = ()):
part_size = 512 * 1024 part_size = 512 * 1024
file_size = os.path.getsize(path) file_size = os.path.getsize(path)
file_total_parts = int(math.ceil(file_size / part_size)) file_total_parts = int(math.ceil(file_size / part_size))
@ -2836,7 +2928,7 @@ class Client:
file_part += 1 file_part += 1
if progress: if progress:
progress(min(file_part * part_size, file_size), file_size) progress(self, min(file_part * part_size, file_size), file_size, *progress_args)
except Exception as e: except Exception as e:
log.error(e, exc_info=True) log.error(e, exc_info=True)
else: else: