From 84f9c2145c19fbcab7b34eb72709c9c3a656cb59 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 11 May 2018 11:56:27 +0200 Subject: [PATCH] Add support for GIF files --- compiler/api/compiler.py | 1 + docs/source/pyrogram/types/GIF.rst | 5 ++ docs/source/pyrogram/types/index.rst | 1 + pyrogram/__init__.py | 2 +- pyrogram/client/ext/utils.py | 11 +++- pyrogram/client/types/__init__.py | 1 + pyrogram/client/types/gif.py | 79 ++++++++++++++++++++++++++++ pyrogram/client/types/message.py | 5 ++ 8 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 docs/source/pyrogram/types/GIF.rst create mode 100644 pyrogram/client/types/gif.py diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 10c0c1dc..7a4b0b06 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -494,6 +494,7 @@ def start(): f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",") f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",") f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",") + f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",") f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",") diff --git a/docs/source/pyrogram/types/GIF.rst b/docs/source/pyrogram/types/GIF.rst new file mode 100644 index 00000000..501f187f --- /dev/null +++ b/docs/source/pyrogram/types/GIF.rst @@ -0,0 +1,5 @@ +GIF +=== + +.. autoclass:: pyrogram.GIF + :members: diff --git a/docs/source/pyrogram/types/index.rst b/docs/source/pyrogram/types/index.rst index 78441878..4cc2c9ca 100644 --- a/docs/source/pyrogram/types/index.rst +++ b/docs/source/pyrogram/types/index.rst @@ -12,6 +12,7 @@ Types PhotoSize Audio Document + GIF Video Voice VideoNote diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e39c94d5..c07ef331 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,7 +29,7 @@ from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Video, + PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video, VideoNote, Voice, CallbackQuery ) from .client.types.reply_markup import ( diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index a6d6374e..d4010df8 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -277,6 +277,7 @@ def parse_messages( venue = None audio = None voice = None + gif = None video = None video_note = None sticker = None @@ -403,7 +404,9 @@ def parse_messages( date=doc.date ) elif types.DocumentAttributeAnimated in attributes: - document = pyrogram_types.Document( + video_attributes = attributes[types.DocumentAttributeVideo] + + gif = pyrogram_types.GIF( file_id=encode( pack( " +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api.core import Object + + +class GIF(Object): + """This object represents a GIF file. + + Attributes: + ID: ``0xb0700025`` + + Args: + file_id (``str``): + Unique identifier for this file. + + width (``int``): + GIF width as defined by sender. + + height (``int``): + GIF height as defined by sender. + + duration (``int``): + Duration of the GIF in seconds as defined by sender. + + thumb (:obj:`PhotoSize `, *optional*): + GIF thumbnail. + + file_name (``str``, *optional*): + GIF file name. + + mime_type (``str``, *optional*): + Mime type of a file as defined by sender. + + file_size (``int``, *optional*): + File size. + + date (``int``, *optional*): + Date the GIF was sent in Unix time. + """ + + ID = 0xb0700025 + + def __init__( + self, + file_id: str, + width: int, + height: int, + duration: int, + thumb=None, + file_name: str = None, + mime_type: str = None, + file_size: int = None, + date: int = None + ): + self.file_id = file_id # string + self.thumb = thumb # flags.0?PhotoSize + self.file_name = file_name # flags.1?string + self.mime_type = mime_type # flags.2?string + self.file_size = file_size # flags.3?int + self.date = date # flags.4?int + self.width = width # int + self.height = height # int + self.duration = duration # int diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 03fb5b8f..d22def65 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -94,6 +94,9 @@ class Message(Object): sticker (:obj:`Sticker `, *optional*): Message is a sticker, information about the sticker. + gif (:obj:`Video `, *optional*): + Message is a GIF, information about the GIF. + video (:obj:`Video `, *optional*): Message is a video, information about the video. @@ -224,6 +227,7 @@ class Message(Object): game=None, photo=None, sticker=None, + gif=None, video=None, voice=None, video_note=None, @@ -274,6 +278,7 @@ class Message(Object): self.game = game # flags.15?Game self.photo = photo # flags.16?Vector self.sticker = sticker # flags.17?Sticker + self.gif = gif self.video = video # flags.18?Video self.voice = voice # flags.19?Voice self.video_note = video_note # flags.20?VideoNote