mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-30 17:43:32 +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 0xb0700015: \"pyrogram.client.types.ChatPhoto\",")
|
||||||
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
|
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
|
||||||
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
|
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 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
|
||||||
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")
|
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
|
PhotoSize
|
||||||
Audio
|
Audio
|
||||||
Document
|
Document
|
||||||
|
GIF
|
||||||
Video
|
Video
|
||||||
Voice
|
Voice
|
||||||
VideoNote
|
VideoNote
|
||||||
|
@ -29,7 +29,7 @@ from .api.errors import Error
|
|||||||
from .client.types import (
|
from .client.types import (
|
||||||
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
|
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
|
||||||
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
|
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
|
||||||
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Video,
|
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
|
||||||
VideoNote, Voice, CallbackQuery
|
VideoNote, Voice, CallbackQuery
|
||||||
)
|
)
|
||||||
from .client.types.reply_markup import (
|
from .client.types.reply_markup import (
|
||||||
|
@ -277,6 +277,7 @@ def parse_messages(
|
|||||||
venue = None
|
venue = None
|
||||||
audio = None
|
audio = None
|
||||||
voice = None
|
voice = None
|
||||||
|
gif = None
|
||||||
video = None
|
video = None
|
||||||
video_note = None
|
video_note = None
|
||||||
sticker = None
|
sticker = None
|
||||||
@ -403,7 +404,9 @@ def parse_messages(
|
|||||||
date=doc.date
|
date=doc.date
|
||||||
)
|
)
|
||||||
elif types.DocumentAttributeAnimated in attributes:
|
elif types.DocumentAttributeAnimated in attributes:
|
||||||
document = pyrogram_types.Document(
|
video_attributes = attributes[types.DocumentAttributeVideo]
|
||||||
|
|
||||||
|
gif = pyrogram_types.GIF(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
"<iiqq",
|
"<iiqq",
|
||||||
@ -413,10 +416,13 @@ def parse_messages(
|
|||||||
doc.access_hash
|
doc.access_hash
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
width=video_attributes.w,
|
||||||
|
height=video_attributes.h,
|
||||||
|
duration=video_attributes.duration,
|
||||||
thumb=parse_thumb(doc.thumb),
|
thumb=parse_thumb(doc.thumb),
|
||||||
file_name=file_name,
|
|
||||||
mime_type=doc.mime_type,
|
mime_type=doc.mime_type,
|
||||||
file_size=doc.size,
|
file_size=doc.size,
|
||||||
|
file_name=file_name,
|
||||||
date=doc.date
|
date=doc.date
|
||||||
)
|
)
|
||||||
elif types.DocumentAttributeVideo in attributes:
|
elif types.DocumentAttributeVideo in attributes:
|
||||||
@ -553,6 +559,7 @@ def parse_messages(
|
|||||||
venue=venue,
|
venue=venue,
|
||||||
audio=audio,
|
audio=audio,
|
||||||
voice=voice,
|
voice=voice,
|
||||||
|
gif=gif,
|
||||||
video=video,
|
video=video,
|
||||||
video_note=video_note,
|
video_note=video_note,
|
||||||
sticker=sticker,
|
sticker=sticker,
|
||||||
|
@ -23,6 +23,7 @@ from .chat_member import ChatMember
|
|||||||
from .chat_photo import ChatPhoto
|
from .chat_photo import ChatPhoto
|
||||||
from .contact import Contact
|
from .contact import Contact
|
||||||
from .document import Document
|
from .document import Document
|
||||||
|
from .gif import GIF
|
||||||
from .input_media_photo import InputMediaPhoto
|
from .input_media_photo import InputMediaPhoto
|
||||||
from .input_media_video import InputMediaVideo
|
from .input_media_video import InputMediaVideo
|
||||||
from .input_phone_contact import InputPhoneContact
|
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*):
|
sticker (:obj:`Sticker <pyrogram.Sticker>`, *optional*):
|
||||||
Message is a sticker, information about the sticker.
|
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*):
|
video (:obj:`Video <pyrogram.Video>`, *optional*):
|
||||||
Message is a video, information about the video.
|
Message is a video, information about the video.
|
||||||
|
|
||||||
@ -224,6 +227,7 @@ class Message(Object):
|
|||||||
game=None,
|
game=None,
|
||||||
photo=None,
|
photo=None,
|
||||||
sticker=None,
|
sticker=None,
|
||||||
|
gif=None,
|
||||||
video=None,
|
video=None,
|
||||||
voice=None,
|
voice=None,
|
||||||
video_note=None,
|
video_note=None,
|
||||||
@ -274,6 +278,7 @@ class Message(Object):
|
|||||||
self.game = game # flags.15?Game
|
self.game = game # flags.15?Game
|
||||||
self.photo = photo # flags.16?Vector<PhotoSize>
|
self.photo = photo # flags.16?Vector<PhotoSize>
|
||||||
self.sticker = sticker # flags.17?Sticker
|
self.sticker = sticker # flags.17?Sticker
|
||||||
|
self.gif = gif
|
||||||
self.video = video # flags.18?Video
|
self.video = video # flags.18?Video
|
||||||
self.voice = voice # flags.19?Voice
|
self.voice = voice # flags.19?Voice
|
||||||
self.video_note = video_note # flags.20?VideoNote
|
self.video_note = video_note # flags.20?VideoNote
|
||||||
|
Loading…
Reference in New Issue
Block a user