44from typing import BinaryIO , Callable , Optional , Union , cast
55
66import pyrogram
7- from pyrogram import raw
8- from pyrogram import types
9- from pyrogram import utils
7+ from pyrogram import raw , types , utils
108from pyrogram .file_id import FileType
119
1210
@@ -20,17 +18,17 @@ async def resolve_to_raw_photo(
2018 raw .types .InputMediaDocument ,
2119]:
2220 """
23- Prepare the photo to be sent in raw
21+ Prepare the photo to be sent in raw.
2422
2523 Parameters:
2624 client (:obj:`~pyrogram.Client`):
27- The client instance
25+ The client instance.
2826
2927 media (:obj:`~pyrogram.types.InputMediaPhoto`):
30- The media to be sent
28+ The media to be sent.
3129
3230 chat_id (``int`` | ``str``, *optional*):
33- The chat id to send the media
31+ The chat id to send the media.
3432
3533 Returns:
3634 :obj:`~pyrogram.raw.types.InputMediaPhoto`
@@ -63,39 +61,40 @@ async def resolve_to_raw_photo(
6361 ),
6462 spoiler = media .has_spoiler ,
6563 )
64+
6665 if re .match ("^https?://" , media .media ):
6766 return raw .types .InputMediaPhotoExternal (
6867 url = media .media ,
6968 spoiler = media .has_spoiler ,
7069 )
70+
7171 return utils .get_input_media_from_file_id (
7272 media .media ,
7373 FileType .PHOTO ,
7474 has_spoiler = media .has_spoiler ,
7575 )
7676
77-
7877async def resolve_to_raw_video (
7978 client : "pyrogram.Client" ,
8079 media : "types.InputMediaVideo" ,
8180 file_name : Optional [str ] = None ,
8281 chat_id : Optional [Union [int , str ]] = None ,
8382) -> Union [raw .types .InputMediaDocument , raw .types .InputMediaDocumentExternal ]:
8483 """
85- Prepare the video to be sent in raw
84+ Prepare the video to be sent in raw.
8685
8786 Parameters:
8887 client (:obj:`~pyrogram.Client`):
89- The client instance
88+ The client instance.
9089
9190 media (:obj:`~pyrogram.types.InputMediaVideo`):
92- The media to be sent
91+ The media to be sent.
9392
9493 file_name (``str``, *optional*):
95- The name of the file
94+ The name of the file.
9695
9796 chat_id (``int`` | ``str``, *optional*):
98- The chat id to send the media
97+ The chat id to send the media.
9998
10099 Returns:
101100 :obj:`~pyrogram.raw.types.InputMediaDocument`
@@ -141,39 +140,40 @@ async def resolve_to_raw_video(
141140 ),
142141 spoiler = media .has_spoiler ,
143142 )
143+
144144 if re .match ("^https?://" , media .media ):
145145 return raw .types .InputMediaDocumentExternal (
146146 url = media .media ,
147147 spoiler = media .has_spoiler ,
148148 )
149+
149150 return utils .get_input_media_from_file_id (
150151 media .media ,
151152 FileType .VIDEO ,
152153 has_spoiler = media .has_spoiler ,
153154 )
154155
155-
156156async def resolve_to_raw_audio (
157157 client : "pyrogram.Client" ,
158158 media : "types.InputMediaAudio" ,
159159 file_name : Optional [str ] = None ,
160160 chat_id : Optional [Union [int , str ]] = None ,
161161) -> Union [raw .types .InputMediaDocument , raw .types .InputMediaDocumentExternal ]:
162162 """
163- Prepare the audio to be sent in raw
163+ Prepare the audio to be sent in raw.
164164
165165 Parameters:
166166 client (:obj:`~pyrogram.Client`):
167- The client instance
167+ The client instance.
168168
169169 media (:obj:`~pyrogram.types.InputMediaAudio`):
170- The media to be sent
170+ The media to be sent.
171171
172172 file_name (``str``, *optional*):
173- The name of the file
173+ The name of the file.
174174
175175 chat_id (``int`` | ``str``, *optional*):
176- The chat id to send the media
176+ The chat id to send the media.
177177
178178 Returns:
179179 :obj:`~pyrogram.raw.types.InputMediaDocument`
@@ -216,12 +216,13 @@ async def resolve_to_raw_audio(
216216 file_reference = uploaded_media .document .file_reference ,
217217 ),
218218 )
219+
219220 if re .match ("^https?://" , media .media ):
220221 return raw .types .InputMediaDocumentExternal (
221222 url = media .media ,
222223 )
223- return utils .get_input_media_from_file_id (media .media , FileType .AUDIO )
224224
225+ return utils .get_input_media_from_file_id (media .media , FileType .AUDIO )
225226
226227async def resolve_to_raw_animation (
227228 client : "pyrogram.Client" ,
@@ -230,20 +231,20 @@ async def resolve_to_raw_animation(
230231 chat_id : Optional [Union [int , str ]] = None ,
231232) -> Union [raw .types .InputMediaDocument , raw .types .InputMediaDocumentExternal ]:
232233 """
233- Prepare the animation to be sent in raw
234+ Prepare the animation to be sent in raw.
234235
235236 Parameters:
236237 client (:obj:`~pyrogram.Client`):
237- The client instance
238+ The client instance.
238239
239240 media (:obj:`~pyrogram.types.InputMediaAnimation`):
240- The media to be sent
241+ The media to be sent.
241242
242243 file_name (``str``, *optional*):
243- The name of the file
244+ The name of the file.
244245
245246 chat_id (``int`` | ``str``, *optional*):
246- The chat id to send the media
247+ The chat id to send the media.
247248
248249 Returns:
249250 :obj:`~pyrogram.raw.types.InputMediaDocument`
@@ -290,39 +291,40 @@ async def resolve_to_raw_animation(
290291 ),
291292 spoiler = media .has_spoiler ,
292293 )
294+
293295 if re .match ("^https?://" , media .media ):
294296 return raw .types .InputMediaDocumentExternal (
295297 url = media .media ,
296298 spoiler = media .has_spoiler ,
297299 )
300+
298301 return utils .get_input_media_from_file_id (
299302 media .media ,
300303 FileType .ANIMATION ,
301304 has_spoiler = media .has_spoiler ,
302305 )
303306
304-
305307async def resolve_to_raw_document (
306308 client : "pyrogram.Client" ,
307309 media : "types.InputMediaDocument" ,
308310 file_name : Optional [str ] = None ,
309311 chat_id : Optional [Union [int , str ]] = None ,
310312) -> Union [raw .types .InputMediaDocument , raw .types .InputMediaDocumentExternal ]:
311313 """
312- Prepare the document to be sent in raw
314+ Prepare the document to be sent in raw.
313315
314316 Parameters:
315317 client (:obj:`~pyrogram.Client`):
316- The client instance
318+ The client instance.
317319
318320 media (:obj:`~pyrogram.types.InputMediaDocument`):
319- The media to be sent
321+ The media to be sent.
320322
321323 file_name (``str``, *optional*):
322- The name of the file
324+ The name of the file.
323325
324326 chat_id (``int`` | ``str``, *optional*):
325- The chat id to send the media
327+ The chat id to send the media.
326328
327329 Returns:
328330 :obj:`~pyrogram.raw.types.InputMediaDocument`
@@ -360,22 +362,24 @@ async def resolve_to_raw_document(
360362 file_reference = uploaded_media .document .file_reference ,
361363 ),
362364 )
365+
363366 if re .match ("^https?://" , media .media ):
364367 return raw .types .InputMediaDocumentExternal (
365368 url = media .media ,
366369 )
370+
367371 return utils .get_input_media_from_file_id (media .media , FileType .DOCUMENT )
368372
369373
370374async def resolve_to_raw_location (
371375 loc : "types.Location" ,
372376) -> Union [raw .types .InputMediaGeoLive , raw .types .InputMediaGeoPoint ]:
373377 """
374- Prepare the location to be sent in raw
378+ Prepare the location to be sent in raw.
375379
376380 Parameters:
377381 loc (:obj:`~pyrogram.types.Location`):
378- The location to be sent
382+ The location to be sent.
379383
380384 Returns:
381385 :obj:`~pyrogram.raw.types.InputMediaGeoLive`
@@ -393,6 +397,7 @@ async def resolve_to_raw_location(
393397 period = loc .live_period ,
394398 proximity_notification_radius = loc .proximity_alert_radius ,
395399 )
400+
396401 return raw .types .InputMediaGeoPoint (
397402 geo_point = raw .types .InputGeoPoint (
398403 lat = loc .latitude or 0 ,
@@ -414,23 +419,23 @@ async def resolve_to_raw_sticker(
414419 raw .types .InputMediaDocument ,
415420]:
416421 """
417- Prepare the sticker to be sent in raw
422+ Prepare the sticker to be sent in raw.
418423
419424 Parameters:
420425 client (:obj:`~pyrogram.Client`):
421- The client instance
426+ The client instance.
422427
423428 sticker (:obj:`~pyrogram.types.InputMediaSticker`):
424- The media to be sent
429+ The media to be sent.
425430
426431 emoji (``str``, *optional*):
427- The emoji to be associated with the sticker
432+ The emoji to be associated with the sticker.
428433
429434 progress (``Callable``, *optional*):
430- A callable to be called with the progress of the upload
435+ A callable to be called with the progress of the upload.
431436
432437 progress_args (``tuple``, *optional*):
433- The arguments to be passed to the progress callable
438+ The arguments to be passed to the progress callable.
434439
435440 Returns:
436441 :obj:`~pyrogram.raw.types.InputMediaUploadedDocument`
@@ -442,15 +447,18 @@ async def resolve_to_raw_sticker(
442447 RPCError: In case of a Telegram RPC error.
443448 """
444449 media : Union [BinaryIO , str ] = sticker .media
450+
445451 if isinstance (media , str ):
446452 if os .path .isfile (media ):
447453 file = await client .save_file (
448454 media ,
449455 progress = cast (Callable , progress ),
450456 progress_args = progress_args ,
451457 )
458+
452459 if not file :
453460 raise ValueError ("Failed to upload sticker" )
461+
454462 return raw .types .InputMediaUploadedDocument (
455463 mime_type = client .guess_mime_type (media ) or "image/webp" ,
456464 file = file ,
@@ -464,6 +472,7 @@ async def resolve_to_raw_sticker(
464472 ),
465473 ],
466474 )
475+
467476 if re .match ("^https?://" , media ):
468477 return raw .types .InputMediaDocumentExternal (url = media )
469478
@@ -474,8 +483,10 @@ async def resolve_to_raw_sticker(
474483 progress = cast (Callable , progress ),
475484 progress_args = progress_args ,
476485 )
486+
477487 if not file :
478488 raise ValueError ("Failed to upload sticker" )
489+
479490 return raw .types .InputMediaUploadedDocument (
480491 mime_type = client .guess_mime_type (media .name ) or "image/webp" ,
481492 file = file ,
0 commit comments