diff --git a/pyrogram/client/types/messages_and_media/__init__.py b/pyrogram/client/types/messages_and_media/__init__.py index ae4386d0..d312611b 100644 --- a/pyrogram/client/types/messages_and_media/__init__.py +++ b/pyrogram/client/types/messages_and_media/__init__.py @@ -26,11 +26,12 @@ from .message import Message from .message_entity import MessageEntity from .messages import Messages from .photo import Photo -from .photo_size import PhotoSize from .poll import Poll from .poll_option import PollOption from .sticker import Sticker -from .user_profile_photos import UserProfilePhotos +from .stripped_thumbnail import StrippedThumbnail +from .thumbnail import Thumbnail +from .photos import Photos from .venue import Venue from .video import Video from .video_note import VideoNote @@ -38,5 +39,5 @@ from .voice import Voice __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Messages", "Photo", - "PhotoSize", "Poll", "PollOption", "Sticker", "UserProfilePhotos", "Venue", "Video", "VideoNote", "Voice" + "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Photos", "Venue", "Video", "VideoNote", "Voice" ] diff --git a/pyrogram/client/types/messages_and_media/animation.py b/pyrogram/client/types/messages_and_media/animation.py index cd6e03ab..d729c3ac 100644 --- a/pyrogram/client/types/messages_and_media/animation.py +++ b/pyrogram/client/types/messages_and_media/animation.py @@ -17,10 +17,11 @@ # along with Pyrogram. If not, see . from struct import pack +from typing import List import pyrogram from pyrogram.api import types -from .photo_size import PhotoSize +from .thumbnail import Thumbnail from ..pyrogram_type import PyrogramType from ...ext.utils import encode @@ -41,9 +42,6 @@ class Animation(PyrogramType): duration (``int``): Duration of the animation in seconds as defined by sender. - thumb (:obj:`PhotoSize `, *optional*): - Animation thumbnail. - file_name (``str``, *optional*): Animation file name. @@ -55,9 +53,12 @@ class Animation(PyrogramType): date (``int``, *optional*): Date the animation was sent in Unix time. + + thumbnails (List of :obj:`Thumbnail`, *optional*): + Animation thumbnails. """ - __slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date", "width", "height", "duration"] + __slots__ = ["file_id", "file_name", "mime_type", "file_size", "date", "width", "height", "duration", "thumbnails"] def __init__( self, @@ -67,16 +68,15 @@ class Animation(PyrogramType): width: int, height: int, duration: int, - thumb: PhotoSize = None, file_name: str = None, mime_type: str = None, file_size: int = None, - date: int = None + date: int = None, + thumbnails: List[Thumbnail] = None, ): super().__init__(client) self.file_id = file_id - self.thumb = thumb self.file_name = file_name self.mime_type = mime_type self.file_size = file_size @@ -84,10 +84,15 @@ class Animation(PyrogramType): self.width = width self.height = height self.duration = duration + self.thumbnails = thumbnails @staticmethod - def _parse(client, animation: types.Document, video_attributes: types.DocumentAttributeVideo, - file_name: str) -> "Animation": + def _parse( + client, + animation: types.Document, + video_attributes: types.DocumentAttributeVideo, + file_name: str + ) -> "Animation": return Animation( file_id=encode( pack( @@ -101,10 +106,10 @@ class Animation(PyrogramType): width=getattr(video_attributes, "w", 0), height=getattr(video_attributes, "h", 0), duration=getattr(video_attributes, "duration", 0), - thumb=PhotoSize._parse(client, animation.thumbs), mime_type=animation.mime_type, file_size=animation.size, file_name=file_name, date=animation.date, + thumbnails=Thumbnail._parse(client, animation), client=client ) diff --git a/pyrogram/client/types/messages_and_media/audio.py b/pyrogram/client/types/messages_and_media/audio.py index 76181a22..ccea2f3c 100644 --- a/pyrogram/client/types/messages_and_media/audio.py +++ b/pyrogram/client/types/messages_and_media/audio.py @@ -17,10 +17,11 @@ # along with Pyrogram. If not, see . from struct import pack +from typing import List import pyrogram from pyrogram.api import types -from .photo_size import PhotoSize +from .thumbnail import Thumbnail from ..pyrogram_type import PyrogramType from ...ext.utils import encode @@ -35,9 +36,6 @@ class Audio(PyrogramType): duration (``int``): Duration of the audio in seconds as defined by sender. - thumb (:obj:`PhotoSize`, *optional*): - Thumbnail of the music file album cover. - file_name (``str``, *optional*): Audio file name. @@ -55,9 +53,14 @@ class Audio(PyrogramType): title (``str``, *optional*): Title of the audio as defined by sender or by audio tags. + + thumbnails (List of :obj:`Thumbnail`, *optional*): + Thumbnails of the music file album cover. """ - __slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date", "duration", "performer", "title"] + __slots__ = [ + "file_id", "file_name", "mime_type", "file_size", "date", "duration", "performer", "title", "thumbnails" + ] def __init__( self, @@ -65,18 +68,17 @@ class Audio(PyrogramType): client: "pyrogram.BaseClient" = None, file_id: str, duration: int, - thumb: PhotoSize = None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None, performer: str = None, - title: str = None + title: str = None, + thumbnails: List[Thumbnail] = None, ): super().__init__(client) self.file_id = file_id - self.thumb = thumb self.file_name = file_name self.mime_type = mime_type self.file_size = file_size @@ -84,10 +86,15 @@ class Audio(PyrogramType): self.duration = duration self.performer = performer self.title = title + self.thumbnails = thumbnails @staticmethod - def _parse(client, audio: types.Document, audio_attributes: types.DocumentAttributeAudio, - file_name: str) -> "Audio": + def _parse( + client, + audio: types.Document, + audio_attributes: types.DocumentAttributeAudio, + file_name: str + ) -> "Audio": return Audio( file_id=encode( pack( @@ -103,8 +110,8 @@ class Audio(PyrogramType): title=audio_attributes.title, mime_type=audio.mime_type, file_size=audio.size, - thumb=PhotoSize._parse(client, audio.thumbs), file_name=file_name, date=audio.date, + thumbnails=Thumbnail._parse(client, audio), client=client ) diff --git a/pyrogram/client/types/messages_and_media/document.py b/pyrogram/client/types/messages_and_media/document.py index 394d5e14..654516e8 100644 --- a/pyrogram/client/types/messages_and_media/document.py +++ b/pyrogram/client/types/messages_and_media/document.py @@ -17,10 +17,11 @@ # along with Pyrogram. If not, see . from struct import pack +from typing import List import pyrogram from pyrogram.api import types -from .photo_size import PhotoSize +from .thumbnail import Thumbnail from ..pyrogram_type import PyrogramType from ...ext.utils import encode @@ -32,9 +33,6 @@ class Document(PyrogramType): file_id (``str``): Unique file identifier. - thumb (:obj:`PhotoSize`, *optional*): - Document thumbnail as defined by sender. - file_name (``str``, *optional*): Original filename as defined by sender. @@ -46,29 +44,32 @@ class Document(PyrogramType): date (``int``, *optional*): Date the document was sent in Unix time. + + thumbnails (List of :obj:`Thumbnail`, *optional*): + Document thumbnails as defined by sender. """ - __slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date"] + __slots__ = ["file_id", "file_name", "mime_type", "file_size", "date", "thumbnails"] def __init__( self, *, client: "pyrogram.BaseClient" = None, file_id: str, - thumb: PhotoSize = None, file_name: str = None, mime_type: str = None, file_size: int = None, - date: int = None + date: int = None, + thumbnails: List[Thumbnail] = None, ): super().__init__(client) self.file_id = file_id - self.thumb = thumb self.file_name = file_name self.mime_type = mime_type self.file_size = file_size - self.date = date + self.date = date, + self.thumbnails = thumbnails @staticmethod def _parse(client, document: types.Document, file_name: str) -> "Document": @@ -82,10 +83,10 @@ class Document(PyrogramType): document.access_hash ) ), - thumb=PhotoSize._parse(client, document.thumbs), file_name=file_name, mime_type=document.mime_type, file_size=document.size, date=document.date, + thumbnails=Thumbnail._parse(client, document), client=client ) diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py index 8d60d59a..ca42c3eb 100644 --- a/pyrogram/client/types/messages_and_media/photo.py +++ b/pyrogram/client/types/messages_and_media/photo.py @@ -16,13 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from base64 import b64encode from struct import pack from typing import List import pyrogram from pyrogram.api import types -from .photo_size import PhotoSize +from .thumbnail import Thumbnail from ..pyrogram_type import PyrogramType from ...ext.utils import encode @@ -31,74 +30,65 @@ class Photo(PyrogramType): """A Photo. Parameters: - id (``str``): + file_id (``str``): Unique identifier for this photo. + width (``int``): + Photo width. + + height (``int``): + Photo height. + + file_size (``int``): + File size. + date (``int``): Date the photo was sent in Unix time. - sizes (List of :obj:`PhotoSize`): + thumbnails (List of :obj:`Thumbnail`): Available sizes of this photo. """ - __slots__ = ["id", "date", "sizes"] + __slots__ = ["file_id", "width", "height", "file_size", "date", "thumbnails"] def __init__( self, *, client: "pyrogram.BaseClient" = None, - id: str, + file_id: str, + width: int, + height: int, + file_size: int, date: int, - sizes: List[PhotoSize] + thumbnails: List[Thumbnail] ): super().__init__(client) - self.id = id + self.file_id = file_id + self.width = width + self.height = height + self.file_size = file_size self.date = date - self.sizes = sizes + self.thumbnails = thumbnails @staticmethod - def _parse(client, photo: types.Photo): + def _parse(client, photo: types.Photo) -> "Photo": if isinstance(photo, types.Photo): - raw_sizes = photo.sizes - sizes = [] - - for raw_size in raw_sizes: - if isinstance(raw_size, (types.PhotoSize, types.PhotoCachedSize)): - if isinstance(raw_size, types.PhotoSize): - file_size = raw_size.size - elif isinstance(raw_size, types.PhotoCachedSize): - file_size = len(raw_size.bytes) - else: - file_size = 0 - - loc = raw_size.location - - if isinstance(loc, types.FileLocation): - size = PhotoSize( - file_id=encode( - pack( - ". from struct import pack +from typing import List import pyrogram from pyrogram.api import types -from .photo_size import PhotoSize +from .thumbnail import Thumbnail from ..pyrogram_type import PyrogramType from ...ext.utils import encode @@ -41,9 +42,6 @@ class Video(PyrogramType): duration (``int``): Duration of the video in seconds as defined by sender. - thumb (:obj:`PhotoSize`, *optional*): - Video thumbnail. - file_name (``str``, *optional*): Video file name. @@ -58,11 +56,14 @@ class Video(PyrogramType): date (``int``, *optional*): Date the video was sent in Unix time. + + thumbnails (List of :obj:`Thumbnail`, *optional*): + Video thumbnails. """ __slots__ = [ - "file_id", "width", "height", "duration", "thumb", "file_name", "mime_type", "supports_streaming", "file_size", - "date" + "file_id", "width", "height", "duration", "file_name", "mime_type", "supports_streaming", "file_size", "date", + "thumbnails" ] def __init__( @@ -73,12 +74,12 @@ class Video(PyrogramType): width: int, height: int, duration: int, - thumb: PhotoSize = None, file_name: str = None, mime_type: str = None, supports_streaming: bool = None, file_size: int = None, - date: int = None + date: int = None, + thumbnails: List[Thumbnail] = None ): super().__init__(client) @@ -86,16 +87,20 @@ class Video(PyrogramType): self.width = width self.height = height self.duration = duration - self.thumb = thumb self.file_name = file_name self.mime_type = mime_type self.supports_streaming = supports_streaming self.file_size = file_size self.date = date + self.thumbnails = thumbnails @staticmethod - def _parse(client, video: types.Document, video_attributes: types.DocumentAttributeVideo, - file_name: str) -> "Video": + def _parse( + client, + video: types.Document, + video_attributes: types.DocumentAttributeVideo, + file_name: str + ) -> "Video": return Video( file_id=encode( pack( @@ -109,11 +114,11 @@ class Video(PyrogramType): width=video_attributes.w, height=video_attributes.h, duration=video_attributes.duration, - thumb=PhotoSize._parse(client, video.thumbs), file_name=file_name, mime_type=video.mime_type, supports_streaming=video_attributes.supports_streaming, file_size=video.size, date=video.date, + thumbnails=Thumbnail._parse(client, video), client=client ) diff --git a/pyrogram/client/types/messages_and_media/video_note.py b/pyrogram/client/types/messages_and_media/video_note.py index 133ccae0..34f5972f 100644 --- a/pyrogram/client/types/messages_and_media/video_note.py +++ b/pyrogram/client/types/messages_and_media/video_note.py @@ -17,10 +17,11 @@ # along with Pyrogram. If not, see . from struct import pack +from typing import List import pyrogram from pyrogram.api import types -from .photo_size import PhotoSize +from .thumbnail import Thumbnail from ..pyrogram_type import PyrogramType from ...ext.utils import encode @@ -38,9 +39,6 @@ class VideoNote(PyrogramType): duration (``int``): Duration of the video in seconds as defined by sender. - thumb (:obj:`PhotoSize`, *optional*): - Video thumbnail. - mime_type (``str``, *optional*): MIME type of the file as defined by sender. @@ -49,9 +47,12 @@ class VideoNote(PyrogramType): date (``int``, *optional*): Date the video note was sent in Unix time. + + thumbnails (List of :obj:`Thumbnail`, *optional*): + Video thumbnails. """ - __slots__ = ["file_id", "thumb", "mime_type", "file_size", "date", "length", "duration"] + __slots__ = ["file_id", "mime_type", "file_size", "date", "length", "duration", "thumbnails"] def __init__( self, @@ -60,7 +61,7 @@ class VideoNote(PyrogramType): file_id: str, length: int, duration: int, - thumb: PhotoSize = None, + thumbnails: List[Thumbnail] = None, mime_type: str = None, file_size: int = None, date: int = None @@ -68,12 +69,12 @@ class VideoNote(PyrogramType): super().__init__(client) self.file_id = file_id - self.thumb = thumb self.mime_type = mime_type self.file_size = file_size self.date = date self.length = length self.duration = duration + self.thumbnails = thumbnails @staticmethod def _parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote": @@ -89,9 +90,9 @@ class VideoNote(PyrogramType): ), length=video_attributes.w, duration=video_attributes.duration, - thumb=PhotoSize._parse(client, video_note.thumbs), file_size=video_note.size, mime_type=video_note.mime_type, date=video_note.date, + thumbnails=Thumbnail._parse(client, video_note), client=client )