From c660d3a7d0f977f321686463089b3e6fa57a8494 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:43:29 +0200 Subject: [PATCH 1/2] Fix PhotoSize not having date anymore --- pyrogram/client/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 20a3e50c..ba584aed 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -711,7 +711,9 @@ class Client(Methods, BaseClient): file_name = "{}_{}_{}{}".format( media_type_str, - datetime.fromtimestamp(media.date or time.time()).strftime("%Y-%m-%d_%H-%M-%S"), + datetime.fromtimestamp( + getattr(media, "date", None) or time.time() + ).strftime("%Y-%m-%d_%H-%M-%S"), self.rnd_id(), extension ) From c85aa5dab2941ddacd154dc2fc672c318001281c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:43:43 +0200 Subject: [PATCH 2/2] Fix Photo downloads --- pyrogram/client/methods/download_media.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/download_media.py b/pyrogram/client/methods/download_media.py index 89b0f61d..20179d08 100644 --- a/pyrogram/client/methods/download_media.py +++ b/pyrogram/client/methods/download_media.py @@ -77,7 +77,12 @@ class DownloadMedia(BaseClient): """ if isinstance(message, pyrogram_types.Message): if message.photo: - media = message.photo.sizes[-1] + media = pyrogram_types.Document( + file_id=message.photo.sizes[-1].file_id, + file_size=message.photo.sizes[-1].file_size, + mime_type="", + date=message.photo.date + ) elif message.audio: media = message.audio elif message.document: @@ -96,6 +101,7 @@ class DownloadMedia(BaseClient): return elif isinstance(message, ( pyrogram_types.Photo, + pyrogram_types.PhotoSize, pyrogram_types.Audio, pyrogram_types.Document, pyrogram_types.Video, @@ -104,7 +110,15 @@ class DownloadMedia(BaseClient): pyrogram_types.Sticker, pyrogram_types.GIF )): - media = message + if isinstance(message, pyrogram_types.Photo): + media = pyrogram_types.Document( + file_id=message.sizes[-1].file_id, + file_size=message.sizes[-1].file_size, + mime_type="", + date=message.date + ) + else: + media = message elif isinstance(message, str): media = pyrogram_types.Document( file_id=message,