Skip to content

Commit 95de5f7

Browse files
authored
Fix determining video sticker resolution. Add sticker duration to Sticker type (pyrogram#1065)
1 parent 6c34c83 commit 95de5f7

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

pyrogram/methods/messages/get_custom_emoji_stickers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ async def get_custom_emoji_stickers(
5050

5151
sticker = await types.Sticker._parse(
5252
self, item,
53-
attributes[raw.types.DocumentAttributeImageSize],
53+
attributes[raw.types.DocumentAttributeImageSize] if raw.types.DocumentAttributeImageSize in attributes else None,
5454
attributes[raw.types.DocumentAttributeCustomEmoji],
55-
attributes[raw.types.DocumentAttributeFilename].file_name
55+
attributes[raw.types.DocumentAttributeFilename].file_name,
56+
attributes[raw.types.DocumentAttributeVideo] if raw.types.DocumentAttributeVideo in attributes else None
5657
)
5758

5859
stickers.append(sticker)

pyrogram/types/messages_and_media/message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@ async def _parse(
700700
client, doc,
701701
attributes.get(raw.types.DocumentAttributeImageSize, None),
702702
attributes[raw.types.DocumentAttributeSticker],
703-
file_name
703+
file_name,
704+
attributes.get(raw.types.DocumentAttributeVideo, None)
704705
)
705706
media_type = enums.MessageMediaType.STICKER
706707
elif raw.types.DocumentAttributeVideo in attributes:

pyrogram/types/messages_and_media/sticker.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class Sticker(Object):
5050
is_video (``bool``):
5151
True, if the sticker is a video sticker
5252
53+
duration (``int``):
54+
Video sticker duration in seconds.
55+
5356
file_name (``str``, *optional*):
5457
Sticker file name.
5558
@@ -84,6 +87,7 @@ def __init__(
8487
height: int,
8588
is_animated: bool,
8689
is_video: bool,
90+
duration: int = None,
8791
file_name: str = None,
8892
mime_type: str = None,
8993
file_size: int = None,
@@ -148,7 +152,8 @@ async def _parse(
148152
sticker: "raw.types.Document",
149153
image_size_attributes: "raw.types.DocumentAttributeImageSize",
150154
sticker_attributes: "raw.types.DocumentAttributeSticker",
151-
file_name: str
155+
file_name: str,
156+
video_attributes: "raw.types.DocumentAttributeVideo"
152157
) -> "Sticker":
153158
sticker_set = sticker_attributes.stickerset
154159

@@ -170,10 +175,11 @@ async def _parse(
170175
file_unique_type=FileUniqueType.DOCUMENT,
171176
media_id=sticker.id
172177
).encode(),
173-
width=image_size_attributes.w if image_size_attributes else 512,
174-
height=image_size_attributes.h if image_size_attributes else 512,
178+
width=image_size_attributes.w if image_size_attributes else (video_attributes.w if video_attributes else 512),
179+
height=image_size_attributes.h if image_size_attributes else (video_attributes.h if video_attributes else 512),
175180
is_animated=sticker.mime_type == "application/x-tgsticker",
176181
is_video=sticker.mime_type == "video/webm",
182+
duration=video_attributes.duration if video_attributes else None,
177183
# TODO: mask_position
178184
set_name=set_name,
179185
emoji=sticker_attributes.alt or None,

0 commit comments

Comments
 (0)