Add ttl_seconds attribute to Voice and VideoNote class

This commit is contained in:
KurimuzonAkuma 2024-02-24 13:32:55 +03:00
parent 313dd665e7
commit 7556d3e386
3 changed files with 19 additions and 6 deletions

View File

@ -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)

View File

@ -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
)

View File

@ -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
)