o
    -˜Žj—h  ã                   @   s¨   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZmZ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 d d	lmZ e  e¡ZG d
d„ dƒZdS )é    N)Údatetime)Ú	MediaInfo)ÚUnionÚListÚOptionalÚCallable)Úenums)Úraw)Útypes)Úutils)ÚFileTypec                ,   @   sº   e Zd Z																	ddddeeef deed  ded	ed
edededeeef deeef deded ded de	dedededede
deded f*dd„ZdS ) ÚSendMediaGroupN© Úselfzpyrogram.ClientÚchat_idÚmedia)ztypes.InputMediaPhotoztypes.InputMediaVideoztypes.InputMediaAudioztypes.InputMediaDocumentztypes.InputMediaAnimationÚdisable_notificationÚmessage_thread_idÚbusiness_connection_idÚreply_to_message_idÚreply_to_story_idÚreply_to_chat_idÚreply_to_monoforum_idÚ
quote_textÚquote_entitiesztypes.MessageEntityÚ
parse_modezenums.ParseModeÚschedule_dateÚprotect_contentÚallow_paid_broadcastÚmessage_effect_idÚinvert_mediaÚprogressÚprogress_argsÚreturnztypes.Messagec                 Ã   sŒ
  �g }t j| ||||||	|
||d�
I dH }|D �]Ñ}t|tjƒrót|jtƒr³tj 	|j¡rm| j
|j||d�I dH }|  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�|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| j
|j||d�I dH }|  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�|jd�}�nÙt|tjƒ�st|tjƒ�rt|jtƒ�r	d
}tj 	|j¡�rÂzt  !|j¡}W n t"�y/   t|tjƒ�r+dnd
}Y nw t#dd„ |j$D ƒƒ�s=d}tjj%|�rEdn|j&�pJd|j'|j(|j)d�tjj*|j+�p_tj ,|j¡d�g}|�rn| -tj .¡ ¡ |  
|j/¡I dH }| j
|j||d�I dH }|  tjjj|  |¡I dH tjj0|||j|  1|j¡�pŸd||d�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�|jd�}�n
t d|j¡�rÿ|  tjjj|  |¡I dH tjj5|j|jd	�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�|jd�}�nÍt  |jtj6¡}�nÃ|  
|j/¡I dH }| j
|j||d�I dH }|  tjjj|  |¡I dH tjj0|||j|  1t7|jddƒ¡�p>dtjj%|j&�pFd|j'|j(|j)d�tjj*|j+�p[t7|jddƒd�gd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�|jd�}�nMt|tj8ƒ�r®t|jtƒ�rAtj 	|j¡�rþ|  
|j/¡I dH }| j
|j||d�I dH }|  tjjj|  |¡I dH tjj0|  1|j¡�pÂd||tjj9|j'|j:|j;d�tjj*|j+�pÜtj ,|j¡d�gd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�d�}�nÎt d|j¡�r7|  tjjj|  |¡I dH tjj5|jd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�d�}�n•t  |jtj<¡}�n‹|  
|j/¡I dH }| j
|j||d�I dH }|  tjjj|  |¡I dH tjj0|  1t7|jddƒ¡�prd||tjj9|j'|j:|j;d�tjj*|j+�pŒt7|jddƒd�gd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�d�}�nt|tj2ƒ�rÃt|jtƒ�rbtj 	|j¡�r!|  
|j/¡I dH }| j
|j||d�I dH }|  tjjj|  |¡I dH tjj0|  1|j¡�pñd||tjj*|j+�p tj ,|j¡d�gd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�d�}n«t d|j¡�rY|  tjjj|  |¡I dH tjj5|jd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�d�}nst  |jtj=¡}nj|  
|j/¡I dH }| j
|j||d�I dH }|  tjjj|  |¡I dH tjj0|  1t7|jddƒ¡�p“d||tjj*|j+�p¢t7|jddƒd�gd�d�¡I dH }tjj2tjj3|j4j|j4j|j4jd�d�}n	t>|j?j@› d�ƒ‚| -tjjAd(||  B¡ dœt  C| |jD|jE|jF¡I dH ¤Ž¡ qtjjjG|  |¡I dH ||�púd|t  H|¡||||d�	}|du�r| jtjjI||d �d!d"�I dH }n
| j|d!d"�I dH }t jJ| tjjjKd#d„ tLd$d%„ |jMƒD ƒ|jN|jOd&�|d'�I dH S ))uc  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).
                You can also use chat public link in form of *t.me/<username>* (str).

            media (List of :obj:`~pyrogram.types.InputMediaPhoto`, :obj:`~pyrogram.types.InputMediaVideo`, :obj:`~pyrogram.types.InputMediaAudio`, :obj:`~pyrogram.types.InputMediaDocument` and :obj:`~pyrogram.types.InputMediaAnimation`):
                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.

            message_thread_id (``int``, *optional*):
                Unique identifier for the target message thread (topic) of the forum.
                for forum supergroups only.

            business_connection_id (``str``, *optional*):
                Business connection identifier.
                for business bots only.

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

            reply_to_story_id (``int``, *optional*):
                Unique identifier for the target story.

            reply_to_chat_id (``int`` | ``str``, *optional*):
                Unique identifier for the origin chat.
                for reply to message from another chat.
                You can also use chat public link in form of *t.me/<username>* (str).

            reply_to_monoforum_id (``int`` | ``str``, *optional*):
                Unique identifier for the target user of monoforum.
                for reply to message from monoforum.
                for channel administrators only.

            quote_text (``str``, *optional*):
                Text to quote.
                for reply_to_message only.

            quote_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*):
                List of special entities that appear in quote_text, which can be specified instead of *parse_mode*.
                for reply_to_message only.

            parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
                By default, quote_text are parsed using both Markdown and HTML styles.
                You can combine both syntaxes together.
                For quote_text.

            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.

            allow_paid_broadcast (``bool``, *optional*):
                Pass True to allow the message to ignore regular broadcast limits for a small fee; for bots only.

            message_effect_id (``int`` ``64-bit``, *optional*):
                Unique identifier of the message effect to be added to the message; for private chats only.

            invert_media (``bool``, *optional*):
                Inverts the position of the media and caption.

            progress (``Callable``, *optional*):
                Pass a callback function to view the file transmission progress.
                The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
                detailed description) and will be called back each time a new file chunk has been successfully
                transmitted.

            progress_args (``tuple``, *optional*):
                Extra custom arguments for the progress callback function.
                You can pass anything you need to be available in the progress callback scope; for example, a Message
                object or a Client instance in order to edit the message with the updated progress status.

        Other Parameters:
            current (``int``):
                The amount of bytes transmitted so far.

            total (``int``):
                The total size of the file.

            *args (``tuple``, *optional*):
                Extra custom arguments as defined in the ``progress_args`` parameter.
                You can either keep ``*args`` or add every single extra argument in your function signature.

        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")
                    ]
                )
        )
Úclientr   r   r   r   r   r   r   r   r   N)r!   r"   )ÚfileÚspoiler)Úpeerr   )ÚidÚaccess_hashÚfile_reference)r(   r&   z
^https?://)Úurlr&   FTc                 S   s   g | ]}|j d k‘qS )ÚAudio)Ú
track_type)Ú.0Útrackr   r   úg/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/pyrogram/methods/messages/send_media_group.pyÚ
<listcomp>  s    z3SendMediaGroup.send_media_group.<locals>.<listcomp>)Úsupports_streamingÚdurationÚwÚh)Ú	file_namez	video/mp4)r%   Úthumbr&   Ú	mime_typeÚnosound_videoÚ
attributesÚnamez	video.mp4)r%   r7   r&   r8   r:   z
audio/mpeg)r3   Ú	performerÚtitle)r8   r%   r7   r:   )r(   )r+   z	audio.mp3zapplication/zipzfile.zipz- is not a supported type for send_media_group)r   Ú	random_id)	r'   Úmulti_mediaÚsilentÚreply_tor   Ú
noforwardsÚallow_paid_floodskipÚeffectr    )Úconnection_idÚqueryé<   )Úsleep_thresholdc                 S   s   g | ]}|j ‘qS r   )Úmessage)r.   Úmr   r   r0   r1   &  s    c                 S   s"   t | tjjtjjtjjtjjfƒS )N)Ú
isinstancer	   r
   ÚUpdateNewMessageÚUpdateNewChannelMessageÚUpdateNewScheduledMessageÚUpdateBotNewBusinessMessage)Úur   r   r0   Ú<lambda>'  s
   
 ýz1SendMediaGroup.send_media_group.<locals>.<lambda>)ÚmessagesÚusersÚchats)r   r   )Pr   Úget_reply_torK   r
   ÚInputMediaPhotor   ÚstrÚosÚpathÚisfileÚ	save_fileÚinvoker	   Ú	functionsrR   ÚUploadMediaÚresolve_peerÚInputMediaUploadedPhotoÚhas_spoilerÚ
InputPhotoÚphotor(   r)   r*   ÚreÚmatchÚInputMediaPhotoExternalÚget_input_media_from_file_idr   ÚPHOTOÚInputMediaVideoÚInputMediaAnimationr   ÚparseÚOSErrorÚanyÚtracksÚDocumentAttributeVideor2   r3   ÚwidthÚheightÚDocumentAttributeFilenamer6   ÚbasenameÚappendÚDocumentAttributeAnimatedr7   ÚInputMediaUploadedDocumentÚguess_mime_typeÚInputMediaDocumentÚInputDocumentÚdocumentÚInputMediaDocumentExternalÚVIDEOÚgetattrÚInputMediaAudioÚDocumentAttributeAudior<   r=   ÚAUDIOÚDOCUMENTÚ
ValueErrorÚ	__class__Ú__name__ÚInputSingleMediaÚrnd_idÚparse_text_entitiesÚcaptionr   Úcaption_entitiesÚSendMultiMediaÚdatetime_to_timestampÚInvokeWithBusinessConnectionÚparse_messagesÚMessagesÚfilterÚupdatesrS   rT   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r?   rA   Úir%   Úis_animationÚ	videoInfor:   r7   ÚrpcÚrr   r   r0   Úsend_media_group+   s¶  € 
ö
þþ
ÿ
ý
úþþ
ÿ
ý
ú	þþ
ÿ
ý
ú
	ÿ
ýÿüù	úþ
ÿý
úþþ
ÿ
ý
ú	
üùûþ
ÿý
úýúüþ
ÿý
ÿÿþ
ÿ	ý
ÿýúüþ
ÿý
ÿÿüþ
ÿýÿÿþ
ÿ	ýÿÿÿúþ
ÿýÿþýÿ÷
þûû÷ózSendMediaGroup.send_media_group)NNNNNNNNNNNNNNNNr   )r„   Ú
__module__Ú__qualname__r   ÚintrW   r   Úboolr   r   r   Útupler–   r   r   r   r0   r   *   s~    æÿ
þÿý
öõôóò
ñ
ðïîíìëêéèçæår   )ÚloggingrX   rd   r   Úpymediainfor   Útypingr   r   r   r   Úpyrogramr   r	   r
   r   Úpyrogram.file_idr   Ú	getLoggerr„   Úlogr   r   r   r   r0   Ú<module>   s   
