o
    -˜Žj¬  ã                   @   sN   d dl Z d dlmZmZmZ d dlZd dlmZ d dlmZ G dd„ dƒZ	dS )é    N)ÚUnionÚOptionalÚBinaryIO)Útypes)ÚFileIdc                   @   sD   e Zd Z		ddddedef dededeeeef  f
d	d
„ZdS )ÚStreamMediar   Úselfzpyrogram.ClientÚmessageztypes.MessageÚlimitÚoffsetÚreturnc                 C  sÊ   �d}t |tjƒr|D ]}t||dƒ}|dur nqtdƒ‚n|}t |tƒr)|}n|j}t |¡}t|ddƒ}	|dk rP|	dkrCtdƒ‚t	 
|	d d ¡}
||
7 }|  ||	||¡2 z	3 dH W }|V  qX6 dS )as  Stream the media from a message chunk by chunk.

        You can use this method to partially download a file into memory or to selectively download chunks of file.
        The chunk maximum size is 1 MiB (1024 * 1024 bytes).

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

        Parameters:
            message (:obj:`~pyrogram.types.Message` | ``str``):
                Pass a Message containing the media, the media itself (message.audio, message.video, ...) or a file id
                as string.

            limit (``int``, *optional*):
                Limit the amount of chunks to stream.
                Defaults to 0 (stream the whole media).

            offset (``int``, *optional*):
                How many chunks to skip before starting to stream.
                Defaults to 0 (start from the beginning).

        Returns:
            ``Generator``: A generator yielding bytes chunk by chunk

        Example:
            .. code-block:: python

                # Stream the whole media
                async for chunk in app.stream_media(message):
                    print(len(chunk))

                # Stream the first 3 chunks only
                async for chunk in app.stream_media(message, limit=3):
                    print(len(chunk))

                # Stream the rest of the media by skipping the first 3 chunks
                async for chunk in app.stream_media(message, offset=3):
                    print(len(chunk))

                # Stream the last 3 chunks only (negative offset)
                async for chunk in app.stream_media(message, offset=-3):
                    print(len(chunk))
        )	ÚaudioÚdocumentÚphotoÚstickerÚ	animationÚvideoÚvoiceÚ
video_noteÚnew_chat_photoNz3This message doesn't contain any downloadable mediaÚ	file_sizer   zNNegative offsets are not supported for file ids, pass a Message object insteadi   )Ú
isinstancer   ÚMessageÚgetattrÚ
ValueErrorÚstrÚfile_idr   ÚdecodeÚmathÚceilÚget_file)r   r	   r
   r   Úavailable_mediaÚkindÚmediaÚfile_id_strÚfile_id_objr   ÚchunksÚchunk© r(   úc/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/pyrogram/methods/messages/stream_media.pyÚstream_media   s0   €0ÿþ

ÿzStreamMedia.stream_mediaN)r   r   )	Ú__name__Ú
__module__Ú__qualname__r   r   Úintr   r   r*   r(   r(   r(   r)   r      s    üÿ
þýüûr   )
r   Útypingr   r   r   Úpyrogramr   Úpyrogram.file_idr   r   r(   r(   r(   r)   Ú<module>   s   