From 1e779a91b72cce36075c9b32d0786067b7f17eec Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 16 Jan 2022 12:42:00 +0100 Subject: [PATCH] Add progress_callback to download_profile_photo --- telethon/_client/downloads.py | 7 ++++--- telethon/_client/telegramclient.py | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/telethon/_client/downloads.py b/telethon/_client/downloads.py index d472dbcf..0b9f9aaf 100644 --- a/telethon/_client/downloads.py +++ b/telethon/_client/downloads.py @@ -180,7 +180,8 @@ async def download_profile_photo( entity: 'hints.EntityLike', file: 'hints.FileLike' = None, *, - thumb) -> typing.Optional[str]: + thumb, + progress_callback) -> typing.Optional[str]: # hex(crc32(x.encode('ascii'))) for x in # ('User', 'Chat', 'UserFull', 'ChatFull') ENTITIES = (0x2da17977, 0xc5af5d94, 0x1f4661b9, 0xd49a2697) @@ -201,7 +202,7 @@ async def download_profile_photo( return await _download_photo( self, entity.chat_photo, file, date=None, - thumb=thumb, progress_callback=None + thumb=thumb, progress_callback=progress_callback ) for attr in ('username', 'first_name', 'title'): @@ -247,7 +248,7 @@ async def download_profile_photo( full = await self(_tl.fn.channels.GetFullChannel(ie)) return await _download_photo( self, full.full_chat.chat_photo, file, - date=None, progress_callback=None, + date=None, progress_callback=progress_callback, thumb=thumb ) else: diff --git a/telethon/_client/telegramclient.py b/telethon/_client/telegramclient.py index 79e51404..c4b9467b 100644 --- a/telethon/_client/telegramclient.py +++ b/telethon/_client/telegramclient.py @@ -1628,7 +1628,8 @@ class TelegramClient: entity: 'hints.EntityLike', file: 'hints.FileLike' = None, *, - thumb: typing.Union[str, enums.Size] = ()) -> typing.Optional[str]: + thumb: typing.Union[str, enums.Size] = (), + progress_callback: 'hints.ProgressCallback' = None) -> typing.Optional[str]: """ Downloads the profile photo from the given user, chat or channel. @@ -1662,6 +1663,10 @@ class TelegramClient: By default, the largest size (original) is downloaded. + progress_callback (`callable`, optional): + A callback function accepting two parameters: + ``(received bytes, total)``. + Returns `None` if no photo was provided, or if it was Empty. On success the file path is returned since it may differ from the one given.