Skip to content

Commit 84f9c21

Browse files
committed
Add support for GIF files
1 parent 3163532 commit 84f9c21

8 files changed

Lines changed: 102 additions & 3 deletions

File tree

compiler/api/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ def start():
494494
f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",")
495495
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
496496
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
497+
f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",")
497498

498499
f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
499500
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")

docs/source/pyrogram/types/GIF.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
GIF
2+
===
3+
4+
.. autoclass:: pyrogram.GIF
5+
:members:

docs/source/pyrogram/types/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Types
1212
PhotoSize
1313
Audio
1414
Document
15+
GIF
1516
Video
1617
Voice
1718
VideoNote

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .client.types import (
3030
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
3131
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
32-
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, Video,
32+
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
3333
VideoNote, Voice, CallbackQuery
3434
)
3535
from .client.types.reply_markup import (

pyrogram/client/ext/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def parse_messages(
277277
venue = None
278278
audio = None
279279
voice = None
280+
gif = None
280281
video = None
281282
video_note = None
282283
sticker = None
@@ -403,7 +404,9 @@ def parse_messages(
403404
date=doc.date
404405
)
405406
elif types.DocumentAttributeAnimated in attributes:
406-
document = pyrogram_types.Document(
407+
video_attributes = attributes[types.DocumentAttributeVideo]
408+
409+
gif = pyrogram_types.GIF(
407410
file_id=encode(
408411
pack(
409412
"<iiqq",
@@ -413,10 +416,13 @@ def parse_messages(
413416
doc.access_hash
414417
)
415418
),
419+
width=video_attributes.w,
420+
height=video_attributes.h,
421+
duration=video_attributes.duration,
416422
thumb=parse_thumb(doc.thumb),
417-
file_name=file_name,
418423
mime_type=doc.mime_type,
419424
file_size=doc.size,
425+
file_name=file_name,
420426
date=doc.date
421427
)
422428
elif types.DocumentAttributeVideo in attributes:
@@ -553,6 +559,7 @@ def parse_messages(
553559
venue=venue,
554560
audio=audio,
555561
voice=voice,
562+
gif=gif,
556563
video=video,
557564
video_note=video_note,
558565
sticker=sticker,

pyrogram/client/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .chat_photo import ChatPhoto
2424
from .contact import Contact
2525
from .document import Document
26+
from .gif import GIF
2627
from .input_media_photo import InputMediaPhoto
2728
from .input_media_video import InputMediaVideo
2829
from .input_phone_contact import InputPhoneContact

pyrogram/client/types/gif.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from pyrogram.api.core import Object
20+
21+
22+
class GIF(Object):
23+
"""This object represents a GIF file.
24+
25+
Attributes:
26+
ID: ``0xb0700025``
27+
28+
Args:
29+
file_id (``str``):
30+
Unique identifier for this file.
31+
32+
width (``int``):
33+
GIF width as defined by sender.
34+
35+
height (``int``):
36+
GIF height as defined by sender.
37+
38+
duration (``int``):
39+
Duration of the GIF in seconds as defined by sender.
40+
41+
thumb (:obj:`PhotoSize <pyrogram.PhotoSize>`, *optional*):
42+
GIF thumbnail.
43+
44+
file_name (``str``, *optional*):
45+
GIF file name.
46+
47+
mime_type (``str``, *optional*):
48+
Mime type of a file as defined by sender.
49+
50+
file_size (``int``, *optional*):
51+
File size.
52+
53+
date (``int``, *optional*):
54+
Date the GIF was sent in Unix time.
55+
"""
56+
57+
ID = 0xb0700025
58+
59+
def __init__(
60+
self,
61+
file_id: str,
62+
width: int,
63+
height: int,
64+
duration: int,
65+
thumb=None,
66+
file_name: str = None,
67+
mime_type: str = None,
68+
file_size: int = None,
69+
date: int = None
70+
):
71+
self.file_id = file_id # string
72+
self.thumb = thumb # flags.0?PhotoSize
73+
self.file_name = file_name # flags.1?string
74+
self.mime_type = mime_type # flags.2?string
75+
self.file_size = file_size # flags.3?int
76+
self.date = date # flags.4?int
77+
self.width = width # int
78+
self.height = height # int
79+
self.duration = duration # int

pyrogram/client/types/message.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class Message(Object):
9494
sticker (:obj:`Sticker <pyrogram.Sticker>`, *optional*):
9595
Message is a sticker, information about the sticker.
9696
97+
gif (:obj:`Video <pyrogram.Video>`, *optional*):
98+
Message is a GIF, information about the GIF.
99+
97100
video (:obj:`Video <pyrogram.Video>`, *optional*):
98101
Message is a video, information about the video.
99102
@@ -224,6 +227,7 @@ def __init__(
224227
game=None,
225228
photo=None,
226229
sticker=None,
230+
gif=None,
227231
video=None,
228232
voice=None,
229233
video_note=None,
@@ -274,6 +278,7 @@ def __init__(
274278
self.game = game # flags.15?Game
275279
self.photo = photo # flags.16?Vector<PhotoSize>
276280
self.sticker = sticker # flags.17?Sticker
281+
self.gif = gif
277282
self.video = video # flags.18?Video
278283
self.voice = voice # flags.19?Voice
279284
self.video_note = video_note # flags.20?VideoNote

0 commit comments

Comments
 (0)