
    N[ia                     T    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      Z	y)    N)UnionOptionalBinaryIO)types)FileIdc                   H    e Zd Z	 	 d
dddedef   dededeeeef      f
dZy	)StreamMediaselfzpyrogram.Clientmessageztypes.Messagelimitoffsetreturnc                  K   d}t        |t        j                        r#|D ]  }t        ||d      }| n t	        d      |}t        |t
              r|}n|j                  }t        j                  |      }t        |dd      }	|dk  r0|	dk(  rt	        d      t        j                  |	dz  dz        }
||
z  }| j                  ||	||      2 3 d{   }| 7 
6 yw)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chunks               Y/var/www/files/kim/lib/python3.12/site-packages/pyrogram/methods/messages/stream_media.pystream_mediazStreamMedia.stream_media   s     `- gu}}-' Xt4$	X !!VWWEeS!K--KmmK0E;2	A:A~ !qrrYYy4/$67FfF==iO 	 	%K	Os/   1C!BC!CCCC!CC!N)r   r   )	__name__
__module____qualname__r   r   intr   r   r,        r+   r	   r	      s[     	NN+,N N 	N
 
%X&	'Nr2   r	   )
r!   typingr   r   r   pyrogramr   pyrogram.file_idr   r	   r1   r2   r+   <module>r6      s%   &  , ,   #O Or2   