1- # Pyrogram - Telegram MTProto API Client Library for Python
2- # Copyright (C) 2017-present Dan <https://github.com/delivrance>
3- #
4- # This file is part of Pyrogram.
5- #
6- # Pyrogram is free software: you can redistribute it and/or modify
7- # it under the terms of the GNU Lesser General Public License as published
8- # by the Free Software Foundation, either version 3 of the License, or
9- # (at your option) any later version.
10- #
11- # Pyrogram is distributed in the hope that it will be useful,
12- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- # GNU Lesser General Public License for more details.
15- #
16- # You should have received a copy of the GNU Lesser General Public License
17- # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18-
191import os
202import re
213from datetime import datetime
@@ -44,6 +26,7 @@ async def send_video(
4426 width : int = 0 ,
4527 height : int = 0 ,
4628 thumb : Union [str , BinaryIO ] = None ,
29+ cover : Union [str , BinaryIO ] = None , # <-- New cover param added here
4730 file_name : str = None ,
4831 supports_streaming : bool = True ,
4932 disable_notification : bool = None ,
@@ -59,138 +42,27 @@ async def send_video(
5942 progress : Callable = None ,
6043 progress_args : tuple = ()
6144 ) -> Optional ["types.Message" ]:
62- """Send video files.
63-
64- .. include:: /_includes/usable-by/users-bots.rst
65-
66- Parameters:
67- chat_id (``int`` | ``str``):
68- Unique identifier (int) or username (str) of the target chat.
69- For your personal cloud (Saved Messages) you can simply use "me" or "self".
70- For a contact that exists in your Telegram address book you can use his phone number (str).
71-
72- video (``str`` | ``BinaryIO``):
73- Video to send.
74- Pass a file_id as string to send a video that exists on the Telegram servers,
75- pass an HTTP URL as a string for Telegram to get a video from the Internet,
76- pass a file path as string to upload a new video that exists on your local machine, or
77- pass a binary file-like object with its attribute ".name" set for in-memory uploads.
78-
79- caption (``str``, *optional*):
80- Video caption, 0-1024 characters.
81-
82- parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
83- By default, texts are parsed using both Markdown and HTML styles.
84- You can combine both syntaxes together.
85-
86- caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
87- List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
88-
89- has_spoiler (``bool``, *optional*):
90- Pass True if the video needs to be covered with a spoiler animation.
91-
92- ttl_seconds (``int``, *optional*):
93- Self-Destruct Timer.
94- If you set a timer, the video will self-destruct in *ttl_seconds*
95- seconds after it was viewed.
96-
97- duration (``int``, *optional*):
98- Duration of sent video in seconds.
99-
100- width (``int``, *optional*):
101- Video width.
102-
103- height (``int``, *optional*):
104- Video height.
105-
106- thumb (``str`` | ``BinaryIO``, *optional*):
107- Thumbnail of the video sent.
108- The thumbnail should be in JPEG format and less than 200 KB in size.
109- A thumbnail's width and height should not exceed 320 pixels.
110- Thumbnails can't be reused and can be only uploaded as a new file.
111-
112- file_name (``str``, *optional*):
113- File name of the video sent.
114- Defaults to file's path basename.
115-
116- supports_streaming (``bool``, *optional*):
117- Pass True, if the uploaded video is suitable for streaming.
118- Defaults to True.
119-
120- disable_notification (``bool``, *optional*):
121- Sends the message silently.
122- Users will receive a notification with no sound.
123-
124- reply_to_message_id (``int``, *optional*):
125- If the message is a reply, ID of the original message.
126-
127- schedule_date (:py:obj:`~datetime.datetime`, *optional*):
128- Date when the message will be automatically sent.
129-
130- protect_content (``bool``, *optional*):
131- Protects the contents of the sent message from forwarding and saving.
132-
133- reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*):
134- Additional interface options. An object for an inline keyboard, custom reply keyboard,
135- instructions to remove reply keyboard or to force a reply from the user.
136-
137- progress (``Callable``, *optional*):
138- Pass a callback function to view the file transmission progress.
139- The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
140- detailed description) and will be called back each time a new file chunk has been successfully
141- transmitted.
142-
143- progress_args (``tuple``, *optional*):
144- Extra custom arguments for the progress callback function.
145- You can pass anything you need to be available in the progress callback scope; for example, a Message
146- object or a Client instance in order to edit the message with the updated progress status.
147-
148- Other Parameters:
149- current (``int``):
150- The amount of bytes transmitted so far.
151-
152- total (``int``):
153- The total size of the file.
154-
155- *args (``tuple``, *optional*):
156- Extra custom arguments as defined in the ``progress_args`` parameter.
157- You can either keep ``*args`` or add every single extra argument in your function signature.
158-
159- Returns:
160- :obj:`~pyrogram.types.Message` | ``None``: On success, the sent video message is returned, otherwise, in
161- case the upload is deliberately stopped with :meth:`~pyrogram.Client.stop_transmission`, None is returned.
162-
163- Example:
164- .. code-block:: python
165-
166- # Send video by uploading from local file
167- await app.send_video("me", "video.mp4")
168-
169- # Add caption to the video
170- await app.send_video("me", "video.mp4", caption="video caption")
171-
172- # Send self-destructing video
173- await app.send_video("me", "video.mp4", ttl_seconds=10)
174-
175- # Keep track of the progress while uploading
176- async def progress(current, total):
177- print(f"{current * 100 / total:.1f}%")
178-
179- await app.send_video("me", "video.mp4", progress=progress)
18045 """
46+ Send video files with optional cover image.
47+ """
48+
18149 file = None
18250
18351 try :
52+ # Save thumb and cover if provided
53+ thumb = await self .save_file (thumb ) if thumb else None
54+ cover = await self .save_file (cover ) if cover else None # <-- Save cover file
55+
18456 if isinstance (video , str ):
18557 if os .path .isfile (video ):
186- thumb = await self .save_file (thumb )
18758 file = await self .save_file (video , progress = progress , progress_args = progress_args )
18859 media = raw .types .InputMediaUploadedDocument (
18960 mime_type = self .guess_mime_type (video ) or "video/mp4" ,
19061 file = file ,
19162 ttl_seconds = ttl_seconds ,
19263 spoiler = has_spoiler ,
19364 thumb = thumb ,
65+ cover = cover , # <-- Pass cover here
19466 attributes = [
19567 raw .types .DocumentAttributeVideo (
19668 supports_streaming = supports_streaming or None ,
@@ -210,22 +82,22 @@ async def progress(current, total):
21082 else :
21183 media = utils .get_input_media_from_file_id (video , FileType .VIDEO , ttl_seconds = ttl_seconds )
21284 else :
213- thumb = await self .save_file (thumb )
21485 file = await self .save_file (video , progress = progress , progress_args = progress_args )
21586 media = raw .types .InputMediaUploadedDocument (
216- mime_type = self .guess_mime_type (file_name or video . name ) or "video/mp4" ,
87+ mime_type = self .guess_mime_type (file_name or getattr ( video , ' name' , None ) ) or "video/mp4" ,
21788 file = file ,
21889 ttl_seconds = ttl_seconds ,
21990 spoiler = has_spoiler ,
22091 thumb = thumb ,
92+ cover = cover , # <-- Pass cover here
22193 attributes = [
22294 raw .types .DocumentAttributeVideo (
22395 supports_streaming = supports_streaming or None ,
22496 duration = duration ,
22597 w = width ,
22698 h = height
22799 ),
228- raw .types .DocumentAttributeFilename (file_name = file_name or video . name )
100+ raw .types .DocumentAttributeFilename (file_name = file_name or getattr ( video , ' name' , None ) )
229101 ]
230102 )
231103
@@ -253,8 +125,8 @@ async def progress(current, total):
253125 raw .types .UpdateNewScheduledMessage )):
254126 return await types .Message ._parse (
255127 self , i .message ,
256- {i .id : i for i in r .users },
257- {i .id : i for i in r .chats },
128+ {u .id : u for u in r .users },
129+ {c .id : c for c in r .chats },
258130 is_scheduled = isinstance (i , raw .types .UpdateNewScheduledMessage )
259131 )
260132 except StopTransmission :
0 commit comments