Skip to content

Commit 9a1e04f

Browse files
committed
Add cover and start_timestamp in send_video and InputPaidMediaVideo
1 parent 851b174 commit 9a1e04f

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

docs/source/releases/changes-in-this-fork.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Changes in this Fork
2626
| Scheme layer used: 198 |
2727
+------------------------+
2828

29+
- Added the ``cover`` and ``start_timestamp`` parameters in :meth:`~pyrogram.Client.send_video` and :obj:`~pyrogram.types.InputPaidMediaVideo`.
2930
- Added the ``new_video_start_timestamp`` and renamed the ``send_copy`` and ``remove_caption`` parameters in :meth:`~pyrogram.Client.forward_messages` and :meth:`~pyrogram.types.Message.forward`.
3031
- Added the ``gift_count`` to the :obj:`~pyrogram.types.Chat`.
3132
- Added the :meth:`~pyrogram.Client.get_similar_bots`.

pyrogram/methods/messages/send_paid_media.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ async def send_paid_media(
179179
file_reference=media.photo.file_reference
180180
)
181181
)
182-
elif (
183-
isinstance(i, types.InputPaidMediaVideo)
184-
):
182+
elif isinstance(i, types.InputPaidMediaVideo):
185183
if isinstance(i.media, str):
186184
if os.path.isfile(i.media):
187185
attributes = [
@@ -201,7 +199,9 @@ async def send_paid_media(
201199
thumb=await self.save_file(i.thumbnail),
202200
mime_type=self.guess_mime_type(i.media) or "video/mp4",
203201
nosound_video=True,
204-
attributes=attributes
202+
attributes=attributes,
203+
video_cover=await self.save_file(i.cover),
204+
video_timestamp=i.start_timestamp
205205
)
206206
)
207207
)
@@ -218,7 +218,9 @@ async def send_paid_media(
218218
raw.functions.messages.UploadMedia(
219219
peer=await self.resolve_peer(chat_id),
220220
media=raw.types.InputMediaDocumentExternal(
221-
url=i.media
221+
url=i.media,
222+
video_cover=await self.save_file(i.cover),
223+
video_timestamp=i.start_timestamp
222224
)
223225
)
224226
)
@@ -248,7 +250,9 @@ async def send_paid_media(
248250
h=i.height
249251
),
250252
raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "video.mp4"))
251-
]
253+
],
254+
video_cover=await self.save_file(i.cover),
255+
video_timestamp=i.start_timestamp
252256
)
253257
)
254258
)

pyrogram/methods/messages/send_video.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ async def send_video(
6565
view_once: bool = None,
6666
file_name: str = None,
6767
mime_type: str = None,
68+
cover: Optional[Union[str, "io.BytesIO"]] = None,
69+
start_timestamp: int = None,
6870
schedule_date: datetime = None,
6971
reply_to_message_id: int = None,
7072
progress: Callable = None,
@@ -173,6 +175,12 @@ async def send_video(
173175
mime_type (``str``, *optional*):
174176
no docs!
175177
178+
cover (``str`` | :obj:`io.BytesIO`, *optional*):
179+
Cover of the video; pass None to skip cover uploading.
180+
181+
start_timestamp (``int``, *optional*):
182+
Timestamp from which the video playing must start, in seconds.
183+
176184
schedule_date (:py:obj:`~datetime.datetime`, *optional*):
177185
Date when the message will be automatically sent.
178186
@@ -260,13 +268,17 @@ async def progress(current, total):
260268
h=height
261269
),
262270
raw.types.DocumentAttributeFilename(file_name=file_name or os.path.basename(video))
263-
]
271+
],
272+
video_cover=await self.save_file(cover) if cover else None,
273+
video_timestamp=start_timestamp
264274
)
265275
elif re.match("^https?://", video):
266276
media = raw.types.InputMediaDocumentExternal(
267277
url=video,
268278
ttl_seconds=ttl_seconds,
269-
spoiler=has_spoiler
279+
spoiler=has_spoiler,
280+
video_cover=await self.save_file(cover) if cover else None,
281+
video_timestamp=start_timestamp
270282
)
271283
else:
272284
media = utils.get_input_media_from_file_id(
@@ -292,7 +304,9 @@ async def progress(current, total):
292304
h=height
293305
),
294306
raw.types.DocumentAttributeFilename(file_name=file_name or video.name)
295-
]
307+
],
308+
video_cover=await self.save_file(cover) if cover else None,
309+
video_timestamp=start_timestamp
296310
)
297311

298312
reply_to = await utils._get_reply_message_parameters(

pyrogram/types/input_paid_media/input_paid_media_video.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class InputPaidMediaVideo(InputPaidMedia):
5454
supports_streaming (``bool``, *optional*):
5555
Pass True, if the uploaded video is suitable for streaming.
5656
57+
cover (``str`` | :obj:`io.BytesIO`, *optional*):
58+
Cover of the video; pass None to skip cover uploading.
59+
60+
start_timestamp (``int``, *optional*):
61+
Timestamp from which the video playing must start, in seconds.
62+
5763
"""
5864

5965
def __init__(
@@ -63,7 +69,9 @@ def __init__(
6369
width: int = 0,
6470
height: int = 0,
6571
duration: int = 0,
66-
supports_streaming: bool = True
72+
supports_streaming: bool = True,
73+
cover: Optional[Union[str, "io.BytesIO"]] = None,
74+
start_timestamp: int = None
6775
):
6876
super().__init__(media)
6977

@@ -72,3 +80,5 @@ def __init__(
7280
self.height = height
7381
self.duration = duration
7482
self.supports_streaming = supports_streaming
83+
self.cover = cover
84+
self.start_timestamp = start_timestamp

pyrogram/types/input_paid_media/paid_media.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,12 @@ def _parse(
9191
video = types.Video._parse(client, doc, video_attributes, file_name, ttl_seconds)
9292

9393
return types.PaidMediaVideo(
94-
video=video
94+
video=video,
95+
cover=types.Photo._parse(
96+
client,
97+
media.video_cover,
98+
media.ttl_seconds,
99+
media.spoiler
100+
) if media.video_cover else None,
101+
start_timestamp=media.video_timestamp
95102
)

pyrogram/types/input_paid_media/paid_media_video.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from typing import Optional
20+
1921
import pyrogram
2022
from pyrogram import types
2123

@@ -30,13 +32,23 @@ class PaidMediaVideo(PaidMedia):
3032
video (:obj:`~pyrogram.types.Video`):
3133
The video.
3234
35+
cover (:obj:`~pyrogram.types.Photo`, *optional*):
36+
Cover of the video.
37+
38+
start_timestamp (``int``, *optional*):
39+
Timestamp from which the video playing must start, in seconds.
40+
3341
"""
3442

3543
def __init__(
3644
self,
3745
*,
38-
video: "types.Video" = None
46+
video: "types.Video" = None,
47+
cover: Optional["types.Photo"] = None,
48+
start_timestamp: Optional[int] = None
3949
):
4050
super().__init__()
4151

4252
self.video = video
53+
self.cover = cover
54+
self.start_timestamp = start_timestamp

0 commit comments

Comments
 (0)