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
19+ from typing import Optional , List
2020
21- from pyrogram import raw
22- from pyrogram import types
23- from pyrogram .parser import Parser
21+ import pyrogram
22+ from pyrogram import raw , types , utils
2423from .inline_query_result import InlineQueryResult
2524
2625
2726class InlineQueryResultVideo (InlineQueryResult ):
28- """Link to a video.
27+ """Link to a page containing an embedded video player or a video file .
2928
30- By default, this video will be sent by the user with optional caption.
29+ By default, this video file will be sent by the user with an optional caption.
3130 Alternatively, you can use *input_message_content* to send a message with the specified content instead of the
3231 video.
3332
@@ -38,21 +37,31 @@ class InlineQueryResultVideo(InlineQueryResult):
3837 thumb_url (``str``):
3938 URL of the thumbnail (jpeg only) for the video.
4039
40+ title (``str``):
41+ Title for the result.
42+
4143 id (``str``, *optional*):
4244 Unique identifier for this result, 1-64 bytes.
4345 Defaults to a randomly generated UUID4.
4446
45- title (``str``, *optional*):
46- Title for the result.
47+ mime_type (``str``):
48+ Mime type of the content of video url, "text/html" or "video/mp4".
49+ Defaults to "video/mp4".
50+
51+ video_width (``int``):
52+ Video width.
4753
48- mime_type (``str``, *optional*):
49- Mime type of the content of video url, “text/html” or “video/mp4”.
54+ video_height (``int``):
55+ Video height.
56+
57+ video_duration (``int``):
58+ Video duration in seconds.
5059
5160 description (``str``, *optional*):
5261 Short description of the result.
5362
5463 caption (``str``, *optional*):
55- Caption of the video to be sent, 0-1024 characters.
64+ Caption of the photo to be sent, 0-1024 characters.
5665
5766 parse_mode (``str``, *optional*):
5867 By default, texts are parsed using both Markdown and HTML styles.
@@ -61,8 +70,11 @@ class InlineQueryResultVideo(InlineQueryResult):
6170 Pass "html" to enable HTML-style parsing only.
6271 Pass None to completely disable style parsing.
6372
73+ caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
74+ List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
75+
6476 reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
65- An InlineKeyboardMarkup object.
77+ Inline keyboard attached to the message
6678
6779 input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
6880 Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is
@@ -73,42 +85,43 @@ def __init__(
7385 self ,
7486 video_url : str ,
7587 thumb_url : str ,
88+ title : str ,
7689 id : str = None ,
77- title : str = None ,
78- mime_type : str = None ,
90+ mime_type : str = "video/mp4" ,
91+ video_width : int = 0 ,
92+ video_height : int = 0 ,
93+ video_duration : int = 0 ,
7994 description : str = None ,
8095 caption : str = "" ,
8196 parse_mode : Optional [str ] = object ,
97+ caption_entities : List ["types.MessageEntity" ] = None ,
8298 reply_markup : "types.InlineKeyboardMarkup" = None ,
8399 input_message_content : "types.InputMessageContent" = None
84100 ):
85101 super ().__init__ ("video" , id , input_message_content , reply_markup )
86102
87103 self .video_url = video_url
88-
89104 self .thumb_url = thumb_url
90105 self .title = title
91-
92- if mime_type != "text/html" and mime_type != "video/mp4" :
93- raise ValueError ("Invalid mime type" )
94-
95- self .mime_type = mime_type
106+ self .video_width = video_width
107+ self .video_height = video_height
108+ self .video_duration = video_duration
96109 self .description = description
97110 self .caption = caption
98111 self .parse_mode = parse_mode
99- self .reply_markup = reply_markup
100-
101- if mime_type == "text/html" and input_message_content is None :
102- raise ValueError ("input_message_content is required for videos with `text/html` mime type" )
103-
104- self .input_message_content = input_message_content
112+ self .caption_entities = caption_entities
113+ self .mime_type = mime_type
105114
106- async def write (self ):
115+ async def write (self , client : "pyrogram.Client" ):
107116 video = raw .types .InputWebDocument (
108117 url = self .video_url ,
109118 size = 0 ,
110119 mime_type = self .mime_type ,
111- attributes = []
120+ attributes = [raw .types .DocumentAttributeVideo (
121+ duration = self .video_duration ,
122+ w = self .video_width ,
123+ h = self .video_height
124+ )]
112125 )
113126
114127 thumb = raw .types .InputWebDocument (
@@ -118,6 +131,10 @@ async def write(self):
118131 attributes = []
119132 )
120133
134+ message , entities = (await utils .parse_text_entities (
135+ client , self .caption , self .parse_mode , self .caption_entities
136+ )).values ()
137+
121138 return raw .types .InputBotInlineResult (
122139 id = self .id ,
123140 type = self .type ,
@@ -126,11 +143,12 @@ async def write(self):
126143 thumb = thumb ,
127144 content = video ,
128145 send_message = (
129- await self .input_message_content .write (self .reply_markup )
146+ await self .input_message_content .write (client , self .reply_markup )
130147 if self .input_message_content
131148 else raw .types .InputBotInlineMessageMediaAuto (
132- reply_markup = self .reply_markup .write () if self .reply_markup else None ,
133- ** await (Parser (None )).parse (self .caption , self .parse_mode )
149+ reply_markup = await self .reply_markup .write (client ) if self .reply_markup else None ,
150+ message = message ,
151+ entities = entities
134152 )
135153 )
136154 )
0 commit comments