2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Add progress parameter

This commit is contained in:
Dan 2018-03-08 10:23:48 +01:00
parent cc49815cc5
commit 6b6122be92

View File

@ -1014,7 +1014,8 @@ class Client:
parse_mode: str = "", parse_mode: str = "",
ttl_seconds: int = None, ttl_seconds: int = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""Use this method to send photos. """Use this method to send photos.
Args: Args:
@ -1054,7 +1055,7 @@ class Client:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
file = self.save_file(photo) file = self.save_file(photo, progress=progress)
while True: while True:
try: try:
@ -1085,7 +1086,8 @@ class Client:
performer: str = None, performer: str = None,
title: str = None, title: str = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""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.
@ -1131,7 +1133,7 @@ class Client:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
file = self.save_file(audio) file = self.save_file(audio, progress=progress)
while True: while True:
try: try:
@ -1167,7 +1169,8 @@ class Client:
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""Use this method to send general files. """Use this method to send general files.
Args: Args:
@ -1202,7 +1205,7 @@ class Client:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
file = self.save_file(document) file = self.save_file(document, progress=progress)
while True: while True:
try: try:
@ -1231,7 +1234,8 @@ class Client:
chat_id: int or str, chat_id: int or str,
sticker: str, sticker: str,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""Use this method to send .webp stickers. """Use this method to send .webp stickers.
Args: Args:
@ -1257,7 +1261,7 @@ class Client:
Raises: Raises:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
file = self.save_file(sticker) file = self.save_file(sticker, progress=progress)
while True: while True:
try: try:
@ -1293,7 +1297,8 @@ class Client:
thumb: str = None, thumb: str = None,
supports_streaming: bool = None, supports_streaming: bool = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""Use this method to send video files. """Use this method to send video files.
Args: Args:
@ -1345,7 +1350,7 @@ class Client:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
file = self.save_file(video) file = self.save_file(video, progress=progress)
file_thumb = None if thumb is None else self.save_file(thumb) file_thumb = None if thumb is None else self.save_file(thumb)
while True: while True:
@ -1385,7 +1390,8 @@ class Client:
parse_mode: str = "", parse_mode: str = "",
duration: int = 0, duration: int = 0,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""Use this method to send audio files. """Use this method to send audio files.
Args: Args:
@ -1423,7 +1429,7 @@ class Client:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
style = self.html if parse_mode.lower() == "html" else self.markdown style = self.html if parse_mode.lower() == "html" else self.markdown
file = self.save_file(voice) file = self.save_file(voice, progress=progress)
while True: while True:
try: try:
@ -1457,7 +1463,8 @@ class Client:
duration: int = 0, duration: int = 0,
length: int = 1, length: int = 1,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = None): reply_to_message_id: int = None,
progress: callable = None):
"""Use this method to send video messages. """Use this method to send video messages.
Args: Args:
@ -1489,7 +1496,7 @@ class Client:
Raises: Raises:
:class:`pyrogram.Error` :class:`pyrogram.Error`
""" """
file = self.save_file(video_note) file = self.save_file(video_note, progress=progress)
while True: while True:
try: try:
@ -1519,6 +1526,7 @@ class Client:
else: else:
return r return r
# TODO: Add progress parameter
def send_media_group(self, def send_media_group(self,
chat_id: int or str, chat_id: int or str,
media: list, media: list,
@ -1973,7 +1981,11 @@ class Client:
) )
# TODO: Remove redundant code # TODO: Remove redundant code
def save_file(self, path: str, file_id: int = None, file_part: int = 0): def save_file(self,
path: str,
file_id: int = None,
file_part: int = 0,
progress: callable = None):
part_size = 512 * 1024 part_size = 512 * 1024
file_size = os.path.getsize(path) file_size = os.path.getsize(path)
file_total_parts = math.ceil(file_size / part_size) file_total_parts = math.ceil(file_size / part_size)
@ -2013,6 +2025,9 @@ class Client:
md5_sum.update(chunk) md5_sum.update(chunk)
file_part += 1 file_part += 1
if progress:
progress(file_part * part_size, file_size)
except Exception as e: except Exception as e:
log.error(e) log.error(e)
else: else: