
    ia                     T    S SK r S SKJrJrJr  S SKrS SKJr  S SKJr   " S S5      r	g)    N)UnionOptionalBinaryIO)types)FileIdc                   T    \ rS rSr  SSSS\S\4   S\S\S\\\\4      4
S	 jjr	S
r
g)StreamMedia   selfzpyrogram.Clientmessageztypes.Messagelimitoffsetreturnc                  #    Sn[        U[        R                  5      (       a%  U H  n[        XS5      nUc  M    O   [	        S5      eUn[        U[
        5      (       a  UnOUR                  n[        R                  " U5      n[        USS5      n	US:  a1  U	S:X  a  [	        S5      e[        R                  " U	S-  S-  5      n
X:-  nU R                  XX#5        Sh  vN nU7v   M   N
 g7f)a  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               S/app/mltbenv/lib/python3.13/site-packages/pyrogram/methods/messages/stream_media.pystream_mediaStreamMedia.stream_media   s     `- gu}}--'t4$	 ( !!VWWEeS!!K--KmmK0E;2	A:A~ !qrrYYy4/$67FF==O 	%K	Os/   4C/B!C/C-C+ C-#C/+C--C/ N)r   r   )__name__
__module____qualname____firstlineno__r   r   intr   r   r-   __static_attributes__r/       r,   r	   r	      sa     	NN+,N N 	N
 
%X&	'N Nr6   r	   )
r"   typingr   r   r   pyrogramr   pyrogram.file_idr   r	   r/   r6   r,   <module>r:      s%   &  , ,   #O Or6   