2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Add support for video stickers

Add Sticker.is_video attribute
This commit is contained in:
Dan 2022-02-01 11:38:58 +01:00
parent b676297ca9
commit 05bfaa3d87
2 changed files with 14 additions and 8 deletions

View File

@ -674,6 +674,14 @@ class Message(Object, Update):
video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None) video_attributes = attributes.get(raw.types.DocumentAttributeVideo, None)
animation = types.Animation._parse(client, doc, video_attributes, file_name) animation = types.Animation._parse(client, doc, video_attributes, file_name)
media_type = "animation" media_type = "animation"
elif raw.types.DocumentAttributeSticker in attributes:
sticker = await types.Sticker._parse(
client, doc,
attributes.get(raw.types.DocumentAttributeImageSize, None),
attributes[raw.types.DocumentAttributeSticker],
file_name
)
media_type = "sticker"
elif raw.types.DocumentAttributeVideo in attributes: elif raw.types.DocumentAttributeVideo in attributes:
video_attributes = attributes[raw.types.DocumentAttributeVideo] video_attributes = attributes[raw.types.DocumentAttributeVideo]
@ -683,14 +691,6 @@ class Message(Object, Update):
else: else:
video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds) video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds)
media_type = "video" media_type = "video"
elif raw.types.DocumentAttributeSticker in attributes:
sticker = await types.Sticker._parse(
client, doc,
attributes.get(raw.types.DocumentAttributeImageSize, None),
attributes[raw.types.DocumentAttributeSticker],
file_name
)
media_type = "sticker"
else: else:
document = types.Document._parse(client, doc, file_name) document = types.Document._parse(client, doc, file_name)
media_type = "document" media_type = "document"

View File

@ -46,6 +46,9 @@ class Sticker(Object):
is_animated (``bool``): is_animated (``bool``):
True, if the sticker is animated True, if the sticker is animated
is_video (``bool``):
True, if the sticker is a video sticker
file_name (``str``, *optional*): file_name (``str``, *optional*):
Sticker file name. Sticker file name.
@ -79,6 +82,7 @@ class Sticker(Object):
width: int, width: int,
height: int, height: int,
is_animated: bool, is_animated: bool,
is_video: bool,
file_name: str = None, file_name: str = None,
mime_type: str = None, mime_type: str = None,
file_size: int = None, file_size: int = None,
@ -98,6 +102,7 @@ class Sticker(Object):
self.width = width self.width = width
self.height = height self.height = height
self.is_animated = is_animated self.is_animated = is_animated
self.is_video = is_video
self.emoji = emoji self.emoji = emoji
self.set_name = set_name self.set_name = set_name
self.thumbs = thumbs self.thumbs = thumbs
@ -167,6 +172,7 @@ class Sticker(Object):
width=image_size_attributes.w if image_size_attributes else 512, width=image_size_attributes.w if image_size_attributes else 512,
height=image_size_attributes.h if image_size_attributes else 512, height=image_size_attributes.h if image_size_attributes else 512,
is_animated=sticker.mime_type == "application/x-tgsticker", is_animated=sticker.mime_type == "application/x-tgsticker",
is_video=sticker.mime_type == "video/webm",
# TODO: mask_position # TODO: mask_position
set_name=set_name, set_name=set_name,
emoji=sticker_attributes.alt or None, emoji=sticker_attributes.alt or None,