Skip to content

Commit ba26c4d

Browse files
authored
Video_cover and video_timestamp (#141)
1 parent 68c77e7 commit ba26c4d

3 files changed

Lines changed: 84 additions & 4 deletions

File tree

pyrogram/methods/messages/send_video.py

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ async def send_video(
4343
duration: int = 0,
4444
width: int = 0,
4545
height: int = 0,
46+
video_start_timestamp: int = 0,
47+
video_cover: Union[str, BinaryIO] = None,
4648
thumb: Union[str, BinaryIO] = None,
4749
file_name: str = None,
4850
supports_streaming: bool = True,
@@ -88,7 +90,7 @@ async def send_video(
8890
video (``str`` | ``BinaryIO``):
8991
Video to send.
9092
Pass a file_id as string to send a video that exists on the Telegram servers,
91-
pass an HTTP URL as a string for Telegram to get a video from the Internet,
93+
pass a HTTP URL as a string for Telegram to get a video from the Internet,
9294
pass a file path as string to upload a new video that exists on your local machine, or
9395
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
9496
@@ -119,6 +121,15 @@ async def send_video(
119121
height (``int``, *optional*):
120122
Video height.
121123
124+
video_start_timestamp (``int``, *optional*):
125+
Video startpoint, in seconds.
126+
127+
video_cover (``str`` | ``BinaryIO``, *optional*):
128+
Video cover.
129+
Pass a file_id as string to attach a photo that exists on the Telegram servers,
130+
pass a file path as string to upload a new photo civer that exists on your local machine, or
131+
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
132+
122133
thumb (``str`` | ``BinaryIO``, *optional*):
123134
Thumbnail of the video sent.
124135
The thumbnail should be in JPEG format and less than 200 KB in size.
@@ -227,15 +238,53 @@ async def send_video(
227238
# Send self-destructing video
228239
await app.send_video("me", "video.mp4", ttl_seconds=10)
229240
241+
# Add video_cover to the video
242+
await app.send_video(channel_id, "video.mp4", video_cover="photo.jpg")
243+
230244
# Keep track of the progress while uploading
231245
async def progress(current, total):
232246
print(f"{current * 100 / total:.1f}%")
233247
234248
await app.send_video("me", "video.mp4", progress=progress)
235249
"""
236250
file = None
251+
vcover_file = None
252+
vcover_media = None
253+
peer = await self.resolve_peer(chat_id)
237254

238255
try:
256+
if video_cover is not None:
257+
if isinstance(video_cover, str):
258+
if os.path.isfile(video_cover):
259+
vcover_media = await self.invoke(
260+
raw.functions.messages.UploadMedia(
261+
peer=peer,
262+
media=raw.types.InputMediaUploadedPhoto(
263+
file=await self.save_file(video_cover)
264+
)
265+
)
266+
)
267+
elif re.match("^https?://", video_cover):
268+
raise ValueError("Video cover can't be a URL")
269+
else:
270+
vcover_file = utils.get_input_media_from_file_id(video_cover, FileType.PHOTO).id
271+
else:
272+
vcover_media = await self.invoke(
273+
raw.functions.messages.UploadMedia(
274+
peer=peer,
275+
media=raw.types.InputMediaUploadedPhoto(
276+
file=await self.save_file(video_cover)
277+
)
278+
)
279+
)
280+
281+
if vcover_media:
282+
vcover_file = raw.types.InputPhoto(
283+
id=vcover_media.photo.id,
284+
access_hash=vcover_media.photo.access_hash,
285+
file_reference=vcover_media.photo.file_reference
286+
)
287+
239288
if isinstance(video, str):
240289
if os.path.isfile(video):
241290
thumb = await self.save_file(thumb)
@@ -246,6 +295,8 @@ async def progress(current, total):
246295
ttl_seconds=ttl_seconds,
247296
spoiler=has_spoiler,
248297
thumb=thumb,
298+
video_cover=vcover_file,
299+
video_timestamp=video_start_timestamp,
249300
nosound_video=no_sound,
250301
attributes=[
251302
raw.types.DocumentAttributeVideo(
@@ -261,7 +312,9 @@ async def progress(current, total):
261312
media = raw.types.InputMediaDocumentExternal(
262313
url=video,
263314
ttl_seconds=ttl_seconds,
264-
spoiler=has_spoiler
315+
spoiler=has_spoiler,
316+
video_cover=vcover_file,
317+
video_timestamp=video_start_timestamp
265318
)
266319
else:
267320
media = utils.get_input_media_from_file_id(video, FileType.VIDEO, ttl_seconds=ttl_seconds, has_spoiler=has_spoiler)
@@ -274,6 +327,8 @@ async def progress(current, total):
274327
ttl_seconds=ttl_seconds,
275328
spoiler=has_spoiler,
276329
thumb=thumb,
330+
video_cover=vcover_file,
331+
video_timestamp=video_start_timestamp,
277332
nosound_video=no_sound,
278333
attributes=[
279334
raw.types.DocumentAttributeVideo(
@@ -290,7 +345,6 @@ async def progress(current, total):
290345

291346
while True:
292347
try:
293-
peer = await self.resolve_peer(chat_id)
294348
r = await self.invoke(
295349
raw.functions.messages.SendMedia(
296350
peer=peer,

pyrogram/types/messages_and_media/message.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3558,6 +3558,8 @@ async def reply_video(
35583558
duration: int = 0,
35593559
width: int = 0,
35603560
height: int = 0,
3561+
video_start_timestamp: int = 0,
3562+
video_cover: Union[str, BinaryIO] = None,
35613563
thumb: Union[str, BinaryIO] = None,
35623564
supports_streaming: bool = True,
35633565
disable_notification: bool = None,
@@ -3598,7 +3600,7 @@ async def reply_video(
35983600
video (``str``):
35993601
Video to send.
36003602
Pass a file_id as string to send a video that exists on the Telegram servers,
3601-
pass an HTTP URL as a string for Telegram to get a video from the Internet, or
3603+
pass a HTTP URL as a string for Telegram to get a video from the Internet, or
36023604
pass a file path as string to upload a new video that exists on your local machine.
36033605
36043606
quote (``bool``, *optional*):
@@ -3635,6 +3637,15 @@ async def reply_video(
36353637
36363638
height (``int``, *optional*):
36373639
Video height.
3640+
3641+
video_start_timestamp (``int``, *optional*):
3642+
Video startpoint, in seconds.
3643+
3644+
video_cover (``str`` | ``BinaryIO``, *optional*):
3645+
Video cover.
3646+
Pass a file_id as string to attach a photo that exists on the Telegram servers,
3647+
pass a file path as string to upload a new photo civer that exists on your local machine, or
3648+
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
36383649
36393650
thumb (``str`` | ``BinaryIO``, *optional*):
36403651
Thumbnail of the video sent.
@@ -3737,6 +3748,8 @@ async def reply_video(
37373748
duration=duration,
37383749
width=width,
37393750
height=height,
3751+
video_start_timestamp=video_start_timestamp,
3752+
video_cover=video_cover,
37403753
thumb=thumb,
37413754
supports_streaming=supports_streaming,
37423755
disable_notification=disable_notification,

pyrogram/types/messages_and_media/story.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,8 @@ async def reply_video(
11291129
duration: int = 0,
11301130
width: int = 0,
11311131
height: int = 0,
1132+
video_start_timestamp: int = 0,
1133+
video_cover: Union[str, BinaryIO] = None,
11321134
thumb: Union[str, BinaryIO] = None,
11331135
file_name: str = None,
11341136
supports_streaming: bool = True,
@@ -1194,6 +1196,15 @@ async def reply_video(
11941196
height (``int``, *optional*):
11951197
Video height.
11961198
1199+
video_start_timestamp (``int``, *optional*):
1200+
Video startpoint, in seconds.
1201+
1202+
video_cover (``str`` | ``BinaryIO``, *optional*):
1203+
Video cover.
1204+
Pass a file_id as string to attach a photo that exists on the Telegram servers,
1205+
pass a file path as string to upload a new photo civer that exists on your local machine, or
1206+
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
1207+
11971208
thumb (``str`` | ``BinaryIO``, *optional*):
11981209
Thumbnail of the video sent.
11991210
The thumbnail should be in JPEG format and less than 200 KB in size.
@@ -1260,6 +1271,8 @@ async def reply_video(
12601271
duration=duration,
12611272
width=width,
12621273
height=height,
1274+
video_start_timestamp=video_start_timestamp,
1275+
video_cover=video_cover,
12631276
thumb=thumb,
12641277
file_name=file_name,
12651278
supports_streaming=supports_streaming,

0 commit comments

Comments
 (0)