B
    fd2                 @   sn   d dl Z d dlZd dlZd dl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
 G dd dZdS )	    N)Union)raw)types)utils)FileTypec            	   @   s0   e Zd Zd	deeef eddeddddZdS )
EditMessageMediaNzpyrogram.Clientztypes.InputMediaztypes.InlineKeyboardMarkupztypes.Message)selfchat_id
message_idmediareply_markup	file_namereturnc                sX  |j }|j}d\}}	|dk	r8| j||I dH  \}}	t|tjrt|jt	j
sbt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}n4td|jrtjj|j|jd}nt |jt!j"}nt|tj#rHt|jt	j
s<tj|jr| tjjj| |I dH tjj$| %|jpld	| |j&I dH |j| |jI dH tjj'|j(pd|j)|j*|j+d
tjj,|ptj-|jdgddI dH }
tjj.tjj/|
j0j|
j0j|
j0jd|jd}n6td|jr4tjj1|j|jd}nt |jt!j2}nht|tj3rlt|jt	j
svtj|jr6| tjjj| |I dH tjj$| %|jpd| |j&I dH | |jI dH tjj4|j)|j5|j6dtjj,|ptj-|jdgddI dH }tjj.tjj/|j0j|j0j|j0jdd}n2td|jrXtjj1|jd}nt |jt!j7}nDt|tj8rt|jt	j
stj|jrl| tjjj| |I dH tjj$| %|jpd	| |j&I dH |j| |jI dH tjj'd|j)|j*|j+d
tjj,|ptj-|jdtj9 gddI dH }
tjj.tjj/|
j0j|
j0j|
j0jd|jd}n6td|jrtjj1|j|jd}nt |jt!j:}n
t|tj.rt|jt	j
stj|jr~| tjjj| |I dH tjj$| %|jpd| |j&I dH | |jI dH tjj,|p<tj-|jdgddI dH }tjj.tjj/|j0j|j0j|j0jdd}n2td|jrtjj1|jd}nt |jt!j;}| tjjj<| |I dH |||r|=| I dH nd||	dI dH }xZ|j>D ]P}t|tjj?tjj@fr tjAB| |jCdd |jDD dd |jED I dH S q W dS )a  Edit animation, audio, document, photo or video messages.

        If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, the
        message type can be changed arbitrarily.

        .. 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).

            message_id (``int``):
                Message identifier in the chat specified in chat_id.

            media (:obj:`~pyrogram.types.InputMedia`):
                One of the InputMedia objects describing an animation, audio, document, photo or video.

            reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
                An InlineKeyboardMarkup object.

            file_name (``str``, *optional*):
                File name of the media to be sent. Not applicable to photos.
                Defaults to file's path basename.

        Returns:
            :obj:`~pyrogram.types.Message`: On success, the edited message is returned.

        Example:
            .. code-block:: python

                from pyrogram.types import InputMediaPhoto, InputMediaVideo, InputMediaAudio

                # Replace the current media with a local photo
                await app.edit_message_media(chat_id, message_id,
                    InputMediaPhoto("new_photo.jpg"))

                # Replace the current media with a local video
                await app.edit_message_media(chat_id, message_id,
                    InputMediaVideo("new_video.mp4"))

                # Replace the current media with a local audio
                await app.edit_message_media(chat_id, message_id,
                    InputMediaAudio("new_audio.mp3"))
        )NNN)filespoiler)peerr   )idaccess_hashfile_reference)r   r   z
^https?://)urlr   z	video/mp4)supports_streamingdurationwh)r   )	mime_typethumbr   r   
attributesz
audio/mpeg)r   	performertitle)r   r   r   r   )r   )r   Tzapplication/zip)r   r   r   r   messageentitiesc             S   s   i | ]}||j qS  )r   ).0ir!   r!   P/tmp/pip-unpacked-wheel-rcokkf2l/pyrogram/methods/messages/edit_message_media.py
<dictcomp>  s    z7EditMessageMedia.edit_message_media.<locals>.<dictcomp>c             S   s   i | ]}||j qS r!   )r   )r"   r#   r!   r!   r$   r%     s    )Fcaption
parse_modeparserparsevalues
isinstancer   ZInputMediaPhotor   ioBytesIOospathisfileZinvoker   Z	functionsmessagesZ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InputMediaUploadedDocumentZguess_mime_typer   ZDocumentAttributeVideor   r   widthheightZDocumentAttributeFilenamebasenameZInputMediaDocumentZInputDocumentdocumentZInputMediaDocumentExternalZVIDEOZInputMediaAudioZDocumentAttributeAudior   r   ZAUDIOZInputMediaAnimationZDocumentAttributeAnimatedZ	ANIMATIONZDOCUMENTZEditMessagewriteZupdatesZUpdateEditMessageZUpdateEditChannelMessageMessage_parser   ZusersZchats)r   r	   r
   r   r   r   r&   r'   r   r    Zuploaded_mediarr#   r!   r!   r$   edit_message_media    s   6
 
*
 * 
 *z#EditMessageMedia.edit_message_media)NN)__name__
__module____qualname__r   intstrr<   r!   r!   r!   r$   r      s    r   )r,   r.   r2   typingr   Zpyrogramr   r   r   Zpyrogram.file_idr   r   r!   r!   r!   r$   <module>   s   