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)
animation = types.Animation._parse(client, doc, video_attributes, file_name)
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:
video_attributes = attributes[raw.types.DocumentAttributeVideo]
@ -683,14 +691,6 @@ class Message(Object, Update):
else:
video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds)
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:
document = types.Document._parse(client, doc, file_name)
media_type = "document"

View File

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