B
    f’»dÂM  ã               @   sˆ   d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlZd dlmZ d dlm	Z	 d dlm
Z
 d dlmZ e  e¡ZG dd	„ d	ƒZdS )
é    N)Údatetime)ÚUnionÚList)Úraw)Útypes)Úutils)ÚFileTypec            
   @   s>   e Zd Zddeeef eed  eeeeed dœdd„Z	dS )	ÚSendMediaGroupNzpyrogram.Client)ztypes.InputMediaPhotoztypes.InputMediaVideoztypes.InputMediaAudioztypes.InputMediaDocumentztypes.Message)ÚselfÚchat_idÚmediaÚdisable_notificationÚreply_to_message_idÚschedule_dateÚprotect_contentÚreturnc       
      Ã   sü  g }xv|D ]l}t |tjƒr°t |jtƒr:tj |j¡r°|  t	j
jj|  |¡I dH t	jj|  |j¡I dH |jdd¡I dH }t	jjt	jj|jj|jj|jjd|jd}nˆt d|j¡r(|  t	j
jj|  |¡I dH t	jj|j|jdd¡I dH }t	jjt	jj|jj|jj|jjd|jd}nt |jtj¡}nr|  t	j
jj|  |¡I dH t	jj|  |j¡I dH |jdd¡I dH }t	jjt	jj|jj|jj|jjd|jd}n”t |tjƒrt |jtƒr2tj |j¡r¨|  t	j
jj|  |¡I dH t	jj|  |j¡I dH |  |j¡I dH |j|   |j¡p0dt	jj!|j"p@d|j#|j$|j%d	t	jj&tj '|j¡d
gdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jd|jd}nˆt d|j¡r |  t	j
jj|  |¡I dH t	jj+|j|jdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jd|jd}nt |jtj,¡}nÒ|  t	j
jj|  |¡I dH t	jj|  |j¡I dH |  |j¡I dH |j|   t-|jddƒ¡pŽdt	jj!|j"pžd|j#|j$|j%d	t	jj&t-|jddƒd
gdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jd|jd}n<t |tj.ƒr4t |jtƒrptj |j¡rî|  t	j
jj|  |¡I dH t	jj|   |j¡pdd|  |j¡I dH |  |j¡I dH t	jj/|j#|j0|j1dt	jj&tj '|j¡d
gdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jdd}n€t d|j¡r^|  t	j
jj|  |¡I dH t	jj+|jdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jdd}nt |jtj2¡}nÀ|  t	j
jj|  |¡I dH t	jj|   t-|jddƒ¡p¨d|  |j¡I dH |  |j¡I dH t	jj/|j#|j0|j1dt	jj&t-|jddƒd
gdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jdd}nt |tj(ƒr2t |jtƒr†tj |j¡r|  t	j
jj|  |¡I dH t	jj|   |j¡pd|  |j¡I dH |  |j¡I dH t	jj&tj '|j¡d
gdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jdd}n€t d|j¡rt|  t	j
jj|  |¡I dH t	jj+|jdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jdd}nt |jtj3¡}nª|  t	j
jj|  |¡I dH t	jj|   t-|jddƒ¡p¾d|  |j¡I dH |  |j¡I dH t	jj&t-|jddƒd
gdd¡I dH }t	jj(t	jj)|j*j|j*j|j*jdd}nt4|j5j6› dƒ‚| 7t	jj8f ||  9¡ dœ| j: ;|j<|j=¡I dH —Ž¡ qW | jt	j
jj>|  |¡I dH ||p¢d|t ?|¡|dddI dH }	t @| t	jjjAdd„ tBdd„ |	jCƒD ƒ|	jD|	jEd¡I dH S ) us  Send a group of photos or videos as an album.

        .. include:: /_includes/usable-by/users-bots.rst

        Parameters:
            chat_id (``int`` | ``str``):
                Unique identifier (int) or username (str) of the target chat.
                For your personal cloud (Saved Messages) you can simply use "me" or "self".
                For a contact that exists in your Telegram address book you can use his phone number (str).

            media (List of :obj:`~pyrogram.types.InputMediaPhoto`, :obj:`~pyrogram.types.InputMediaVideo`, :obj:`~pyrogram.types.InputMediaAudio` and :obj:`~pyrogram.types.InputMediaDocument`):
                A list describing photos and videos to be sent, must include 2â€“10 items.

            disable_notification (``bool``, *optional*):
                Sends the message silently.
                Users will receive a notification with no sound.

            reply_to_message_id (``int``, *optional*):
                If the message is a reply, ID of the original message.

            schedule_date (:py:obj:`~datetime.datetime`, *optional*):
                Date when the message will be automatically sent.

            protect_content (``bool``, *optional*):
                Protects the contents of the sent message from forwarding and saving.

        Returns:
            List of :obj:`~pyrogram.types.Message`: On success, a list of the sent messages is returned.

        Example:
            .. code-block:: python

                from pyrogram.types import InputMediaPhoto, InputMediaVideo

                await app.send_media_group(
                    "me",
                    [
                        InputMediaPhoto("photo1.jpg"),
                        InputMediaPhoto("photo2.jpg", caption="photo caption"),
                        InputMediaVideo("video.mp4", caption="video caption")
                    ]
                )
        N)ÚfileÚspoiler)Úpeerr   )ÚidÚaccess_hashÚfile_reference)r   r   z
^https?://)Úurlr   z	video/mp4)Úsupports_streamingÚdurationÚwÚh)Ú	file_name)r   Úthumbr   Ú	mime_typeÚ
attributesÚnamez	video.mp4z
audio/mpeg)r   Ú	performerÚtitle)r   r   r   r    )r   )r   z	audio.mp3zapplication/zipzfile.zipz- is not a supported type for send_media_group)r   Z	random_id)r   Úmulti_mediaZsilentZreply_to_msg_idr   Z
noforwardsé<   )Zsleep_thresholdc             S   s   g | ]
}|j ‘qS © )Úmessage)Ú.0Úmr&   r&   úN/tmp/pip-unpacked-wheel-rcokkf2l/pyrogram/methods/messages/send_media_group.pyú
<listcomp>˜  s    z3SendMediaGroup.send_media_group.<locals>.<listcomp>c             S   s   t | tjjtjjtjjfƒS )N)Ú
isinstancer   r   ZUpdateNewMessageZUpdateNewChannelMessageZUpdateNewScheduledMessage)Úur&   r&   r*   Ú<lambda>™  s   
z1SendMediaGroup.send_media_group.<locals>.<lambda>)ÚmessagesÚusersÚchats)Fr,   r   ZInputMediaPhotor   ÚstrÚosÚpathÚisfileZinvoker   Z	functionsr/   ZUploadMediaZresolve_peerZInputMediaUploadedPhotoZ	save_fileZhas_spoilerZ
InputPhotoZphotor   r   r   ÚreÚmatchZInputMediaPhotoExternalr   Zget_input_media_from_file_idr   ZPHOTOZInputMediaVideoZInputMediaUploadedDocumentr   Zguess_mime_typeZDocumentAttributeVideor   r   ÚwidthÚheightZDocumentAttributeFilenameÚbasenameZInputMediaDocumentZInputDocumentÚdocumentZInputMediaDocumentExternalZVIDEOÚgetattrZInputMediaAudioZDocumentAttributeAudior"   r#   ZAUDIOZDOCUMENTÚ
ValueErrorÚ	__class__Ú__name__ÚappendZInputSingleMediaZrnd_idÚparserÚparseÚcaptionZ
parse_modeZSendMultiMediaZdatetime_to_timestampZparse_messagesZMessagesÚfilterZupdatesr0   r1   )
r
   r   r   r   r   r   r   r$   ÚiÚrr&   r&   r*   Úsend_media_group$   s®   9



*


*
****
"
zSendMediaGroup.send_media_group)NNNN)
r?   Ú
__module__Ú__qualname__r   Úintr2   r   Úboolr   rG   r&   r&   r&   r*   r	   "   s
       r	   )Úloggingr3   r6   r   Útypingr   r   Zpyrogramr   r   r   Zpyrogram.file_idr   Ú	getLoggerr?   Úlogr	   r&   r&   r&   r*   Ú<module>   s   
