o
    2j                  
   @   s   d dl mZ d dlZd dlm  mZ d dlmZ ej	de
dejfddZej	ejdd	d
ejej dejdedB dejfddZejejG dd dZdS )    )IteratorN)Streamtypereturnc                 C   sT   | dkrt jS | dkrt jS | dkrt jS | dkrt jS | dkr#t jS td|  )Nvideoaudiosubtitle
attachmentdatazInvalid stream type: )libAVMEDIA_TYPE_VIDEOAVMEDIA_TYPE_AUDIOAVMEDIA_TYPE_SUBTITLEAVMEDIA_TYPE_ATTACHMENTAVMEDIA_TYPE_DATA
ValueErrorr    r   O/var/www/html/whisper/venv/lib/python3.10/site-packages/av/container/streams.py_get_media_type_enum   s   r   F)checkfmtctxenumtyperelatedc                 C   s@   |d u rt | |ddtjd}|S t | |d|jjtjd}|S )Nr   )r   av_find_best_streamcythonNULLptrindex)r   r   r   stream_indexr   r   r   _get_best_stream_index   s   	r!   c                   @   s   e Zd ZdZdd ZejdedejfddZ	dd	 Z
d
d Zdd Zedd Zedd Zedd Zedd Zedd Zdee fddZdd Zd!dedB defdd ZdS )"StreamContainerz

    A tuple-like container of :class:`Stream`.

    ::

        # There are a few ways to pulling out streams.
        first = container.streams[0]
        video = container.streams.video[0]
        audio = container.streams.get(audio=(0, 1))


    c                 C   s
   g | _ d S N)_streamsselfr   r   r   	__cinit__<      
zStreamContainer.__cinit__streamr   c                 C   s&   |j jt| jksJ | j| d S r#   )r   r   lenr$   append)r&   r)   r   r   r   
add_stream?   s   zStreamContainer.add_streamc                 C   
   t | jS r#   )r*   r$   r%   r   r   r   __len__E   r(   zStreamContainer.__len__c                 C   r-   r#   )iterr$   r%   r   r   r   __iter__H   r(   zStreamContainer.__iter__c                 C   s"   t |tr| |d S | |S )Nr   )
isinstanceintget)r&   r   r   r   r   __getitem__K   s   

zStreamContainer.__getitem__c                 C      t dd | jD S )Nc                 s       | ]
}|j d kr|V  qdS )r   Nr   .0sr   r   r   	<genexpr>S       z(StreamContainer.video.<locals>.<genexpr>tupler$   r%   r   r   r   r   Q      zStreamContainer.videoc                 C   r5   )Nc                 s   r6   )r   Nr   r7   r   r   r   r:   W   r;   z(StreamContainer.audio.<locals>.<genexpr>r<   r%   r   r   r   r   U   r>   zStreamContainer.audioc                 C   r5   )Nc                 s   r6   )r   Nr   r7   r   r   r   r:   [   r;   z,StreamContainer.subtitles.<locals>.<genexpr>r<   r%   r   r   r   	subtitlesY   r>   zStreamContainer.subtitlesc                 C   r5   )Nc                 s   r6   )r
   Nr   r7   r   r   r   r:   _   r;   z'StreamContainer.data.<locals>.<genexpr>r<   r%   r   r   r   r
   ]   r>   zStreamContainer.datac                 C   r5   )Nc                 s   r6   )r	   Nr   r7   r   r   r   r:   c   r;   z.StreamContainer.attachments.<locals>.<genexpr>r<   r%   r   r   r   attachmentsa   r>   zStreamContainer.attachmentsc                 c   s    |d u rd S t |tr|V  d S t |tr| j| V  d S t |ttfr4|D ]
}| |E d H  q'd S t |trd| D ]$\}}|dkrH| jnt	| |}t |ttfsW|g}|D ]}|| V  qYq=d S t
dt|)NstreamszArgument must be Stream or int.)r1   r   r2   r$   r=   list_get_streamsdictitemsgetattr	TypeErrorr   )r&   xitemtype_indicesrA   ir   r   r   rC   e   s*   



zStreamContainer._get_streamsc                 O   s4   t | |}|r|| | |p| jdd S )a+  get(streams=None, video=None, audio=None, subtitles=None, data=None)

        Get a selection of :class:`.Stream` as a ``list``.

        Positional arguments may be ``int`` (which is an index into the streams),
        or ``list`` or ``tuple`` of those::

            # Get the first channel.
            streams.get(0)

            # Get the first two audio channels.
            streams.get(audio=(0, 1))

        Keyword arguments (or dicts as positional arguments) as interpreted
        as ``(stream_type, index_value_or_set)`` pairs::

            # Get the first video channel.
            streams.get(video=0)
            # or
            streams.get({'video': 0})

        :class:`.Stream` objects are passed through untouched.

        If nothing is selected, then all streams are returned.

        N)rB   rC   extendr$   )r&   argskwargs	selectionr   r   r   r3   z   s   zStreamContainer.getNr   r   c                C   sR   t | jdkr	dS tt| jd }|jj}t|t||}|dk r$dS | j| S )a  best(type: Literal["video", "audio", "subtitle", "attachment", "data"], /, related: Stream | None)
        Finds the "best" stream in the file. Wraps :ffmpeg:`av_find_best_stream`. Example::

            stream = container.streams.best("video")

        :param type: The type of stream to find
        :param related: A related stream to use as a reference (optional)
        :return: The best stream of the specified type
        :rtype: Stream | None
        r   N)	r*   r$   r   castr   	containerr   r!   r   )r&   r   r   first_streamrR   r    r   r   r   best   s   

zStreamContainer.bestr#   )__name__
__module____qualname____doc__r'   r   cfuncr   voidr,   r.   r0   r4   propertyr   r   r?   r
   r@   r   rC   r3   strrT   r   r   r   r   r"   +   s*    




!r"   )typingr   r   cython.cimports.libavcimportslibavr   cython.cimports.av.streamr   rY   r\   AVMediaTyper   	exceptvalpointerAVFormatContextr2   r!   finalcclassr"   r   r   r   r   <module>   s(    

