Skip to content

Commit 7b14a3d

Browse files
Add view_once parameter in send_video
1 parent 607b731 commit 7b14a3d

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

pyrogram/methods/messages/send_photo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ async def send_photo(
194194
195195
# Send self-destructing photo
196196
await app.send_photo("me", "photo.jpg", ttl_seconds=10)
197+
198+
# Send view-once photo
199+
await app.send_photo("me", "photo.jpg", view_once=True)
197200
"""
198201
if any(
199202
(

pyrogram/methods/messages/send_video.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async def send_video(
3939
caption_entities: List["types.MessageEntity"] = None,
4040
has_spoiler: bool = None,
4141
ttl_seconds: int = None,
42+
view_once: bool = None,
4243
duration: int = 0,
4344
width: int = 0,
4445
height: int = 0,
@@ -116,6 +117,10 @@ async def send_video(
116117
If you set a timer, the video will self-destruct in *ttl_seconds*
117118
seconds after it was viewed.
118119
120+
view_once (``bool``, *optional*):
121+
Self-Destruct Timer.
122+
If True, the photo will self-destruct after it was viewed.
123+
119124
duration (``int``, *optional*):
120125
Duration of sent video in seconds.
121126
@@ -238,6 +243,9 @@ async def send_video(
238243
# Send self-destructing video
239244
await app.send_video("me", "video.mp4", ttl_seconds=10)
240245
246+
# Send view-once video
247+
await app.send_video("me", "video.mp4", view_once=True)
248+
241249
# Add video_cover to the video
242250
await app.send_video(channel_id, "video.mp4", video_cover="photo.jpg")
243251
@@ -349,7 +357,7 @@ async def progress(current, total):
349357
media = raw.types.InputMediaUploadedDocument(
350358
mime_type=self.guess_mime_type(video) or "video/mp4",
351359
file=file,
352-
ttl_seconds=ttl_seconds,
360+
ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds,
353361
spoiler=has_spoiler,
354362
thumb=thumb,
355363
video_cover=vcover_file,
@@ -368,13 +376,13 @@ async def progress(current, total):
368376
elif re.match("^https?://", video):
369377
media = raw.types.InputMediaDocumentExternal(
370378
url=video,
371-
ttl_seconds=ttl_seconds,
379+
ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds,
372380
spoiler=has_spoiler,
373381
video_cover=vcover_file,
374382
video_timestamp=video_start_timestamp
375383
)
376384
else:
377-
media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=ttl_seconds, has_spoiler=has_spoiler)
385+
media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds, has_spoiler=has_spoiler)
378386
media.video_cover = vcover_file
379387
media.video_timestamp = video_start_timestamp
380388
else:
@@ -383,7 +391,7 @@ async def progress(current, total):
383391
media = raw.types.InputMediaUploadedDocument(
384392
mime_type=self.guess_mime_type(file_name or video.name) or "video/mp4",
385393
file=file,
386-
ttl_seconds=ttl_seconds,
394+
ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds,
387395
spoiler=has_spoiler,
388396
thumb=thumb,
389397
video_cover=vcover_file,

pyrogram/types/messages_and_media/message.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,7 @@ async def reply_video(
41514151
has_spoiler: bool = None,
41524152
show_caption_above_media: bool = None,
41534153
ttl_seconds: int = None,
4154+
view_once: bool = None,
41544155
duration: int = 0,
41554156
width: int = 0,
41564157
height: int = 0,
@@ -4230,6 +4231,10 @@ async def reply_video(
42304231
If you set a timer, the video will self-destruct in *ttl_seconds*
42314232
seconds after it was viewed.
42324233
4234+
view_once (``bool``, *optional*):
4235+
Self-Destruct Timer.
4236+
If True, the photo will self-destruct after it was viewed.
4237+
42334238
duration (``int``, *optional*):
42344239
Duration of sent video in seconds.
42354240
@@ -4356,6 +4361,7 @@ async def reply_video(
43564361
has_spoiler=has_spoiler,
43574362
show_caption_above_media=show_caption_above_media,
43584363
ttl_seconds=ttl_seconds,
4364+
view_once=view_once,
43594365
duration=duration,
43604366
width=width,
43614367
height=height,

pyrogram/types/messages_and_media/story.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ async def reply_video(
11901190
caption_entities: List["types.MessageEntity"] = None,
11911191
has_spoiler: bool = None,
11921192
ttl_seconds: int = None,
1193+
view_once: bool = None,
11931194
duration: int = 0,
11941195
width: int = 0,
11951196
height: int = 0,
@@ -1255,6 +1256,10 @@ async def reply_video(
12551256
If you set a timer, the video will self-destruct in *ttl_seconds*
12561257
seconds after it was viewed.
12571258
1259+
view_once (``bool``, *optional*):
1260+
Self-Destruct Timer.
1261+
If True, the photo will self-destruct after it was viewed.
1262+
12581263
duration (``int``, *optional*):
12591264
Duration of sent video in seconds.
12601265
@@ -1344,6 +1349,7 @@ async def reply_video(
13441349
caption_entities=caption_entities,
13451350
has_spoiler=has_spoiler,
13461351
ttl_seconds=ttl_seconds,
1352+
view_once=view_once,
13471353
duration=duration,
13481354
width=width,
13491355
height=height,

0 commit comments

Comments
 (0)