mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-28 00:56:19 +00:00
Add support for GIF files
This commit is contained in:
parent
31635327ca
commit
84f9c2145c
@ -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\",")
|
||||
|
5
docs/source/pyrogram/types/GIF.rst
Normal file
5
docs/source/pyrogram/types/GIF.rst
Normal file
@ -0,0 +1,5 @@
|
||||
GIF
|
||||
===
|
||||
|
||||
.. autoclass:: pyrogram.GIF
|
||||
:members:
|
@ -12,6 +12,7 @@ Types
|
||||
PhotoSize
|
||||
Audio
|
||||
Document
|
||||
GIF
|
||||
Video
|
||||
Voice
|
||||
VideoNote
|
||||
|
@ -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 (
|
||||
|
@ -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(
|
||||
"<iiqq",
|
||||
@ -413,10 +416,13 @@ def parse_messages(
|
||||
doc.access_hash
|
||||
)
|
||||
),
|
||||
width=video_attributes.w,
|
||||
height=video_attributes.h,
|
||||
duration=video_attributes.duration,
|
||||
thumb=parse_thumb(doc.thumb),
|
||||
file_name=file_name,
|
||||
mime_type=doc.mime_type,
|
||||
file_size=doc.size,
|
||||
file_name=file_name,
|
||||
date=doc.date
|
||||
)
|
||||
elif types.DocumentAttributeVideo in attributes:
|
||||
@ -553,6 +559,7 @@ def parse_messages(
|
||||
venue=venue,
|
||||
audio=audio,
|
||||
voice=voice,
|
||||
gif=gif,
|
||||
video=video,
|
||||
video_note=video_note,
|
||||
sticker=sticker,
|
||||
|
@ -23,6 +23,7 @@ from .chat_member import ChatMember
|
||||
from .chat_photo import ChatPhoto
|
||||
from .contact import Contact
|
||||
from .document import Document
|
||||
from .gif import GIF
|
||||
from .input_media_photo import InputMediaPhoto
|
||||
from .input_media_video import InputMediaVideo
|
||||
from .input_phone_contact import InputPhoneContact
|
||||
|
79
pyrogram/client/types/gif.py
Normal file
79
pyrogram/client/types/gif.py
Normal file
@ -0,0 +1,79 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <pyrogram.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
|
@ -94,6 +94,9 @@ class Message(Object):
|
||||
sticker (:obj:`Sticker <pyrogram.Sticker>`, *optional*):
|
||||
Message is a sticker, information about the sticker.
|
||||
|
||||
gif (:obj:`Video <pyrogram.Video>`, *optional*):
|
||||
Message is a GIF, information about the GIF.
|
||||
|
||||
video (:obj:`Video <pyrogram.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<PhotoSize>
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user