Skip to content

Commit

Permalink
Add ttl_seconds attribute to Voice and VideoNote class
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Feb 24, 2024
1 parent 313dd66 commit 7556d3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ async def _parse(
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)
Expand All @@ -936,7 +936,7 @@ async def _parse(
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)
Expand Down
11 changes: 9 additions & 2 deletions pyrogram/types/messages_and_media/video_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -67,7 +70,8 @@ def __init__(
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)

Expand All @@ -76,6 +80,7 @@ def __init__(
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
Expand All @@ -84,7 +89,8 @@ def __init__(
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(
Expand All @@ -103,6 +109,7 @@ def _parse(
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
)
10 changes: 8 additions & 2 deletions pyrogram/types/messages_and_media/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -61,7 +64,8 @@ def __init__(
waveform: bytes = None,
mime_type: str = None,
file_size: int = None,
date: datetime = None
date: datetime = None,
ttl_seconds: int = None
):
super().__init__(client)

Expand All @@ -72,9 +76,10 @@ def __init__(
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,
Expand All @@ -92,5 +97,6 @@ def _parse(client, voice: "raw.types.Document", attributes: "raw.types.DocumentA
file_size=voice.size,
waveform=attributes.waveform,
date=utils.timestamp_to_datetime(voice.date),
ttl_seconds=ttl_seconds,
client=client
)

0 comments on commit 7556d3e

Please sign in to comment.