From 7556d3e3864215386f018692947cdf52a82cb420 Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Sat, 24 Feb 2024 13:32:55 +0300 Subject: [PATCH] Add ttl_seconds attribute to Voice and VideoNote class --- pyrogram/types/messages_and_media/message.py | 4 ++-- pyrogram/types/messages_and_media/video_note.py | 11 +++++++++-- pyrogram/types/messages_and_media/voice.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index bcdc2dea..bfea9e64 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -926,7 +926,7 @@ class Message(Object, Update): video_attributes = attributes[raw.types.DocumentAttributeVideo] if video_attributes.round_message: - video_note = types.VideoNote._parse(client, doc, video_attributes) + video_note = types.VideoNote._parse(client, doc, video_attributes, media.ttl_seconds) media_type = enums.MessageMediaType.VIDEO_NOTE else: video = types.Video._parse(client, doc, video_attributes, file_name, media.ttl_seconds) @@ -936,7 +936,7 @@ class Message(Object, Update): audio_attributes = attributes[raw.types.DocumentAttributeAudio] if audio_attributes.voice: - voice = types.Voice._parse(client, doc, audio_attributes) + voice = types.Voice._parse(client, doc, audio_attributes, media.ttl_seconds) media_type = enums.MessageMediaType.VOICE else: audio = types.Audio._parse(client, doc, audio_attributes, file_name) diff --git a/pyrogram/types/messages_and_media/video_note.py b/pyrogram/types/messages_and_media/video_note.py index 3e6b40d0..9aa70449 100644 --- a/pyrogram/types/messages_and_media/video_note.py +++ b/pyrogram/types/messages_and_media/video_note.py @@ -52,6 +52,9 @@ class VideoNote(Object): date (:py:obj:`~datetime.datetime`, *optional*): Date the video note was sent. + ttl_seconds (``int``, *optional*): + Time-to-live seconds, for one-time media. + thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*): Video thumbnails. """ @@ -67,7 +70,8 @@ class VideoNote(Object): thumbs: List["types.Thumbnail"] = None, mime_type: str = None, file_size: int = None, - date: datetime = None + date: datetime = None, + ttl_seconds: int = None ): super().__init__(client) @@ -76,6 +80,7 @@ class VideoNote(Object): self.mime_type = mime_type self.file_size = file_size self.date = date + self.ttl_seconds = ttl_seconds self.length = length self.duration = duration self.thumbs = thumbs @@ -84,7 +89,8 @@ class VideoNote(Object): def _parse( client, video_note: "raw.types.Document", - video_attributes: "raw.types.DocumentAttributeVideo" + video_attributes: "raw.types.DocumentAttributeVideo", + ttl_seconds: int = None ) -> "VideoNote": return VideoNote( file_id=FileId( @@ -103,6 +109,7 @@ class VideoNote(Object): file_size=video_note.size, mime_type=video_note.mime_type, date=utils.timestamp_to_datetime(video_note.date), + ttl_seconds=ttl_seconds, thumbs=types.Thumbnail._parse(client, video_note), client=client ) diff --git a/pyrogram/types/messages_and_media/voice.py b/pyrogram/types/messages_and_media/voice.py index 8d1c15f6..adceafb7 100644 --- a/pyrogram/types/messages_and_media/voice.py +++ b/pyrogram/types/messages_and_media/voice.py @@ -49,6 +49,9 @@ class Voice(Object): date (:py:obj:`~datetime.datetime`, *optional*): Date the voice was sent. + + ttl_seconds (``int``, *optional*): + Time-to-live seconds, for one-time media. """ def __init__( @@ -61,7 +64,8 @@ class Voice(Object): waveform: bytes = None, mime_type: str = None, file_size: int = None, - date: datetime = None + date: datetime = None, + ttl_seconds: int = None ): super().__init__(client) @@ -72,9 +76,10 @@ class Voice(Object): self.mime_type = mime_type self.file_size = file_size self.date = date + self.ttl_seconds = ttl_seconds @staticmethod - def _parse(client, voice: "raw.types.Document", attributes: "raw.types.DocumentAttributeAudio") -> "Voice": + def _parse(client, voice: "raw.types.Document", attributes: "raw.types.DocumentAttributeAudio", ttl_seconds: int = None) -> "Voice": return Voice( file_id=FileId( file_type=FileType.VOICE, @@ -92,5 +97,6 @@ class Voice(Object): file_size=voice.size, waveform=attributes.waveform, date=utils.timestamp_to_datetime(voice.date), + ttl_seconds=ttl_seconds, client=client )