o
    )Wg\1                     @   s.  d dl mZ d dlmZ ddlmZ ddlmZmZ d dl	m
Z
 d dlZdd	 Zd
d ZG dd de
Zdd Zdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZehdfd$d%Zd*d&d'Zd*d(d)ZdgZdS )+    )unicode_literals)
basestring   )KwargReprNode)escape_charsget_hash_int)objectNc                 C   s&   d}|D ]}t | |rd} |S q|S )NFT)
isinstance)objtypesvalidstream_type r   K/var/www/html/audio_editor/env/lib/python3.10/site-packages/ffmpeg/nodes.py_is_of_types
   s   
r   c                 C   s   d dd | D S )Nz, c                 S   s   g | ]
}d  |j|jqS )z{}.{})format
__module____name__.0xr   r   r   
<listcomp>       z"_get_types_str.<locals>.<listcomp>)join)r   r   r   r   _get_types_str   s   r   c                   @   sT   e Zd ZdZ	dddZdd Zdd Zd	d
 Zdd Ze	dd Z
e	dd ZdS )Streamz^Represents the outgoing edge of an upstream node; may be used to create more downstream nodes.Nc                 C   s8   t ||stdt|t||| _|| _|| _d S )NzHExpected upstream node to be of one of the following type(s): {}; got {})r   	TypeErrorr   r   typenodelabelselector)selfupstream_nodeupstream_label
node_typesupstream_selectorr   r   r   __init__   s   

zStream.__init__c                 C   s   t t| jt| jgS N)r   hashr   r   r!   r   r   r   __hash__'   s   zStream.__hash__c                 C   s   t | t |kS r'   )r(   )r!   otherr   r   r   __eq__*   s   zStream.__eq__c                 C   s>   | j jdd}d}| jrd| j}d|| j|| j j}|S )NF)include_hash z:{}z{}[{!r}{}] <{}>)r   	long_reprr    r   r   
short_hash)r!   	node_reprr    outr   r   r   __repr__-   s   zStream.__repr__c                 C   sB   | j durtd| t|tstd|| jj| j|dS )a  
        Select a component (audio, video) of the stream.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input['a'].filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input['v'].hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        Nz!Stream already has a selector: {}z*Expected string index (e.g. 'a'); got {!r}r   r    )	r    
ValueErrorr   r	   r   r   r   streamr   )r!   indexr   r   r   __getitem__7   s
   

zStream.__getitem__c                 C      | d S )a  Select the audio-portion of a stream.

        Some ffmpeg filters drop audio streams, and care must be taken
        to preserve the audio in the final output.  The ``.audio`` and
        ``.video`` operators can be used to reference the audio/video
        portions of a stream so that they can be processed separately
        and then re-combined later in the pipeline.  This dilemma is
        intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the
        way while users may refer to the official ffmpeg documentation
        as to why certain filters drop audio.

        ``stream.audio`` is a shorthand for ``stream['a']``.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input.audio.filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input.video.hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        ar   r)   r   r   r   audioI      zStream.audioc                 C   r9   )a  Select the video-portion of a stream.

        Some ffmpeg filters drop audio streams, and care must be taken
        to preserve the audio in the final output.  The ``.audio`` and
        ``.video`` operators can be used to reference the audio/video
        portions of a stream so that they can be processed separately
        and then re-combined later in the pipeline.  This dilemma is
        intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the
        way while users may refer to the official ffmpeg documentation
        as to why certain filters drop audio.

        ``stream.video`` is a shorthand for ``stream['v']``.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input.audio.filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input.video.hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        vr   r)   r   r   r   videob   r<   zStream.videor'   )r   r   __qualname____doc__r&   r*   r,   r3   r8   propertyr;   r>   r   r   r   r   r      s    


r   c                 C   sV   | d u ri }|S t | trd | i}|S t | ttfr"tt| }|S t | tr)| }|S r'   )r	   r   listtupledict	enumeratestream_spec
stream_mapr   r   r   get_stream_map|   s   

rI   c                 C   sB   g }t |  D ]}t|tstdt|||j q|S )NzExpected Stream; got {})	rB   valuesr	   r   r   r   r   appendr   )rH   nodesr6   r   r   r   get_stream_map_nodes   s   
rM   c                 C   s   t | }t|S r'   )rI   rM   rF   r   r   r   get_stream_spec_nodes   s   rN   c                       s\   e Zd ZdZedd Zedd Zedd Zg i f fdd		ZdddZ	dd Z
  ZS )Nodez	Node basec                 C   sX   |d urt ||k rtd|t ||d ur(t ||kr*td|t |d S d S )Nz,Expected at least {} input stream(s); got {}z+Expected at most {} input stream(s); got {})lenr5   r   )clsrH   
min_inputs
max_inputsr   r   r   __check_input_len   s   zNode.__check_input_lenc                 C   s8   t | D ]}t||stdt|t|qd S )NzKExpected incoming stream(s) to be of one of the following types: {}; got {})rB   rJ   r   r   r   r   r   )rQ   rH   incoming_stream_typesr6   r   r   r   __check_input_types   s   
zNode.__check_input_typesc                 C   s2   i }t | D ]\}}|j|j|jf||< q|S r'   )rB   itemsr   r   r    )rQ   rH   incoming_edge_mapdownstream_labelupstreamr   r   r   __get_incoming_edge_map   s   
zNode.__get_incoming_edge_mapc	                    sR   t |}	| |	|| | |	| | |	}
tt| |
||| || _|| _d S r'   )	rI   _Node__check_input_len_Node__check_input_types_Node__get_incoming_edge_mapsuperrO   r&   _Node__outgoing_stream_type_Node__incoming_stream_types)r!   rG   namerU   outgoing_stream_typerR   rS   argskwargsrH   rX   	__class__r   r   r&      s   

zNode.__init__Nc                 C   s   | j | ||dS )z|Create an outgoing stream originating from this node.

        More nodes may be attached onto the outgoing stream.
        r%   )r`   )r!   r   r    r   r   r   r6      s   zNode.streamc                 C   s(   t |tr| j|j|jdS | j|dS )aj  Create an outgoing stream originating from this node; syntactic sugar for ``self.stream(label)``.
        It can also be used to apply a selector: e.g. ``node[0:'a']`` returns a stream with label 0 and
        selector ``'a'``, which is the same as ``node.stream(label=0, selector='a')``.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input[:'a'].filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input[:'v'].hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        r4   )r   )r	   slicer6   startstop)r!   itemr   r   r   r8      s   
zNode.__getitem__)NN)r   r   r?   r@   classmethodr\   r]   r^   r&   r6   r8   __classcell__r   r   rf   r   rO      s    

	

rO   c                          e Zd Zd fdd	Z  ZS )FilterableStreamNc                    s   t t| ||tth| d S r'   )r_   rp   r&   	InputNode
FilterNoder!   r"   r#   r%   rf   r   r   r&      s   
zFilterableStream.__init__r'   r   r   r?   r&   rn   r   r   rf   r   rp          rp   c                       s2   e Zd ZdZg i f fdd	Zedd Z  ZS )rq   zInputNode typec              
      s$   t t| jd |i tdd||d d S )Nr   rG   rb   rU   rc   rR   rS   rd   re   )r_   rq   r&   rp   )r!   rb   rd   re   rf   r   r   r&      s   

zInputNode.__init__c                 C      t j| jd S Nfilenameospathbasenamere   r)   r   r   r   
short_repr     zInputNode.short_repr)r   r   r?   r@   r&   rA   r~   rn   r   r   rf   r   rq      s
    rq   c                       s.   e Zd Zdg i f fdd	Z	 dd Z  ZS )rr   r   c              
      s&   t t| j||thtd|||d d S Nr   rv   )r_   rr   r&   rp   )r!   rG   rb   rS   rd   re   rf   r   r   r&   	     

zFilterNode.__init__c                    s   | j }| j}| jdv rt|g}dd |D }i  t| D ]\}}t|d}t|d}| |< qdd |D } fddt D }|| }	t| jd}
|	rZ|
dd	|	7 }
t|
d	S )
N)splitasplitc                 S      g | ]}t |d qS \'=:r   r   r   r   r   r         z*FilterNode._get_filter.<locals>.<listcomp>r   c                 S   r   r   r   )r   r=   r   r   r   r   $  r   c                    s   g | ]
}d  | | qS )z{}={})r   )r   k
out_kwargsr   r   r   %  r   z={}:z\'[],;)
rd   re   rb   rP   rB   rW   r   sortedr   r   )r!   outgoing_edgesrd   re   out_argsr   r=   
arg_paramskwarg_paramsparamsparams_textr   r   r   _get_filter  s"   





zFilterNode._get_filter)r   r   r?   r&   r   rn   r   r   rf   r   rr     s    rr   c                       s.   e Zd Zg i f fdd	Zedd Z  ZS )
OutputNodec              
      s&   t t| j||thtdd ||d d S r   )r_   r   r&   rp   OutputStreamr!   r6   rb   rd   re   rf   r   r   r&   1  r   zOutputNode.__init__c                 C   rw   rx   rz   r)   r   r   r   r~   =  r   zOutputNode.short_repr)r   r   r?   r&   rA   r~   rn   r   r   rf   r   r   0  s    r   c                       ro   )r   Nc                    s"   t t| j||ttth|d d S )Nrh   )r_   r   r&   r   
GlobalNodeMergeOutputsNoders   rf   r   r   r&   C  s   

zOutputStream.__init__r'   rt   r   r   rf   r   r   B  ru   r   c                       s   e Zd Z fddZ  ZS )r   c                    s"   t t| j||thtdd d d S )Nr   )rG   rb   rU   rc   rR   rS   )r_   r   r&   r   )r!   streamsrb   rf   r   r   r&   N  s   

zMergeOutputsNode.__init__rt   r   r   rf   r   r   M  s    r   c                       s"   e Zd Zg i f fdd	Z  ZS )r   c              
      s&   t t| j||thtdd||d d S r   )r_   r   r&   r   r   rf   r   r   r&   [  r   zGlobalNode.__init__rt   r   r   rf   r   r   Z  s    r   c                    s    fdd}|S )Nc                    s"   p j  fddD   S )Nc                    s   g | ]}t | qS r   )setattr)r   stream_classfunc	func_namer   r   r   k  s    z6stream_operator.<locals>.decorator.<locals>.<listcomp>)r   )r   rb   stream_classesr   r   	decoratori  s   
z"stream_operator.<locals>.decoratorr   )r   rb   r   r   r   r   stream_operatorh  s   r   c                 C      t th| dS N)r   rb   )r   rp   rb   r   r   r   filter_operatorq     r   c                 C   r   r   )r   r   r   r   r   r   output_operatoru  r   r   r'   )
__future__r   past.builtinsr   dagr   _utilsr   r   builtinsr   r{   r   r   r   rI   rM   rN   rO   rp   rq   rr   r   r   r   r   r   r   r   __all__r   r   r   r   <module>   s0    	e	U(
	

