
    Cg\1                     T   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 Zd	 Z G d
 de
      Zd Zd Zd Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      ZehdfdZd"d Zd"d!ZdgZy)#    )unicode_literals)
basestring   )KwargReprNode)escape_charsget_hash_int)objectNc                 :    d}|D ]  }t        | |      sd} |S  |S )NFT)
isinstance)objtypesvalidstream_types       U/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/ffmpeg/nodes.py_is_of_typesr   
   s4    E c;'EL	 L    c           	          dj                  | D cg c](  }dj                  |j                  |j                        * c}      S c c}w )Nz, z{}.{})joinformat
__module____name__)r   xs     r   _get_types_strr      s2    99N1gnnQ\\1::>NOONs   -Ac                   R    e Zd ZdZ	 d
dZd Zd Zd Zd Ze	d        Z
e	d	        Zy)Streamz^Represents the outgoing edge of an upstream node; may be used to create more downstream nodes.Nc                     t        ||      s-t        dj                  t        |      t	        |                  || _        || _        || _        y )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_selectors        r   __init__zStream.__init__   sO     M:6Zaa":.]0C 
 "	#
)r   c                 h    t        t        | j                        t        | j                        g      S N)r   hashr   r    r"   s    r   __hash__zStream.__hash__'   s#    T$))_d4::.>?@@r   c                 0    t        |       t        |      k(  S r)   )r*   )r"   others     r   __eq__zStream.__eq__*   s    DzT%[((r   c                     | j                   j                  d      }d}| j                  rdj                  | j                        }dj                  || j                  || j                   j
                        }|S )NF)include_hash z:{}z{}[{!r}{}] <{}>)r   	long_reprr!   r   r    
short_hash)r"   	node_reprr!   outs       r   __repr__zStream.__repr__-   se    II''U';	==||DMM2H&&tzz8TYY-A-A
 
r   c                     | j                   t        dj                  |             t        |t              st        dj                  |            | j                  j                  | j                  |      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')
        z!Stream already has a selector: {}z*Expected string index (e.g. 'a'); got {!r}r    r!   )	r!   
ValueErrorr   r   r   r   r   streamr    )r"   indexs     r   __getitem__zStream.__getitem__7   se     ==$@GGMNNE:.HOOPUVWWyydjj5AAr   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')
        a r+   s    r   audiozStream.audioI       . Cyr   c                     | d   S )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+   s    r   videozStream.videob   rB   r   r)   )r   r   __qualname____doc__r'   r,   r/   r7   r=   propertyrA   rE   r@   r   r   r   r      sO    h LP*A)B$  0  r   r   c                     | 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_maps     r   get_stream_maprQ   |   sq    
  
K	(K(

 	 
K$	/)K01
  
K	& 
r   c                     g }t        | j                               D ]P  }t        |t              s#t	        dj                  t        |                  |j                  |j                         R |S )NzExpected Stream; got {})	rJ   valuesr   r   r   r   r   appendr   )rP   nodesr;   s      r   get_stream_map_nodesrV      s`    Ez((*+ "&&)5<<T&\JKKV[[!" Lr   c                 .    t        |       }t        |      S r)   )rQ   rV   rN   s     r   get_stream_spec_nodesrX      s    ,J
++r   c                   f     e Zd ZdZed        Zed        Zed        Zg i f fd	ZddZ	d Z
 xZS )	Nodez	Node basec                     |2t        |      |k  r$t        dj                  |t        |                  |3t        |      |kD  r$t        dj                  |t        |                  y y )Nz,Expected at least {} input stream(s); got {}z+Expected at most {} input stream(s); got {})lenr:   r   )clsrP   
min_inputs
max_inputss       r   __check_input_lenzNode.__check_input_len   sw    !c*o
&B>EEJ 
 #J*(D=DDJ  )E#r   c           	          t        |j                               D ];  }t        ||      rt        dj	                  t        |      t        |                   y )NzKExpected incoming stream(s) to be of one of the following types: {}; got {})rJ   rS   r   r   r   r   r   )r]   rP   incoming_stream_typesr;   s       r   __check_input_typeszNode.__check_input_types   sT    :,,./ 	F(=>ahh&'<=tF| 	r   c                     i }t        |j                               D ]+  \  }}|j                  |j                  |j                  f||<   - |S r)   )rJ   itemsr   r    r!   )r]   rP   incoming_edge_mapdownstream_labelupstreams        r   __get_incoming_edge_mapzNode.__get_incoming_edge_map   sX    *.z/?/?/A*B 	&h!!3./	 ! r   c	                     t        |      }	| j                  |	||       | j                  |	|       | j                  |	      }
t        t
        |   |
|||       || _        || _        y r)   )	rQ   _Node__check_input_len_Node__check_input_types_Node__get_incoming_edge_mapsuperrZ   r'   _Node__outgoing_stream_type_Node__incoming_stream_types)r"   rO   namerb   outgoing_stream_typer^   r_   argskwargsrP   rf   	__class__s              r   r'   zNode.__init__   si     $K0
z:zB  -BC 88DdD"#4dD&I&:#'<$r   c                 *    | j                  | ||      S )z|Create an outgoing stream originating from this node.

        More nodes may be attached onto the outgoing stream.
        r&   )ro   )r"   r    r!   s      r   r;   zNode.stream   s    
 **4(*SSr   c                     t        |t              r'| j                  |j                  |j                        S | j                  |      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')
        r9   )r    )r   slicer;   startstop)r"   items     r   r=   zNode.__getitem__   s:     dE";;TZZ$));DD;;T;**r   )NN)r   r   rF   rG   classmethodrk   rl   rm   r'   r;   r=   __classcell__ru   s   @r   rZ   rZ      sX        ! !$ =(T+r   rZ   c                         e Zd Zd fd	Z xZS )FilterableStreamc                 F    t         t        |   ||t        t        h|       y r)   )rn   r   r'   	InputNode
FilterNoder"   r#   r$   r&   ru   s       r   r'   zFilterableStream.__init__   s"    .>Iz+BDU	
r   r)   r   r   rF   r'   r~   r   s   @r   r   r      s    
 
r   r   c                   8     e Zd ZdZg i f fd	Zed        Z xZS )r   zInputNode typec           
      D    t         t        |   d |i t        dd||       y )Nr   rO   rq   rb   rr   r^   r_   rs   rt   )rn   r   r'   r   )r"   rq   rs   rt   ru   s       r   r'   zInputNode.__init__   s/    i'"$!1 	( 		
r   c                 Z    t         j                  j                  | j                  d         S Nfilenameospathbasenamert   r+   s    r   
short_reprzInputNode.short_repr       wwJ 788r   )r   r   rF   rG   r'   rH   r   r~   r   s   @r   r   r      s$    "$R 

 9 9r   r   c                   .     e Zd Zdg i f fd	Z	 d Z xZS )r   r   c           
      N    t         t        |   ||t        ht        d|||       y Nr   r   )rn   r   r'   r   )r"   rO   rq   r_   rs   rt   ru   s         r   r'   zFilterNode.__init__	  s2    j$(##3"4!1! 	) 		
r   c                 V   | j                   }| j                  }| j                  dv rt        |      g}|D cg c]  }t	        |d       }}i }t        |j                               D ]"  \  }}t	        |d      }t	        |d      }|||<   $ |D cg c]  }t	        |d       }	}t        |      D cg c]  }dj                  |||          }
}|	|
z   }t	        | j                  d      }|r#|dj                  dj                  |            z  }t	        |d      S c c}w c c}w c c}w )N)splitasplitz\'=:z{}={}z={}:z\'[],;)
rs   rt   rq   r\   r   rJ   re   sortedr   r   )r"   outgoing_edgesrs   rt   r   out_args
out_kwargskrD   
arg_paramskwarg_paramsparamsparams_texts                r   _get_filterzFilterNode._get_filter  s$   yy99++'(D7;<!LH-<<
( 	DAqQ)AQ)AJqM	
 :BBAl1h/B
BBHBTUQq*Q-8UUl*"499h75<<(899KK44 = CUs   DD!2D&)r   r   rF   r'   r   r~   r   s   @r   r   r     s    56R 

 5r   r   c                   4     e Zd Zg i f fd	Zed        Z xZS )
OutputNodec           
      N    t         t        |   ||t        ht        dd ||       y r   )rn   r   r'   r   OutputStreamr"   r;   rq   rs   rt   ru   s        r   r'   zOutputNode.__init__1  s2    j$(#3"4!- 	) 		
r   c                 Z    t         j                  j                  | j                  d         S r   r   r+   s    r   r   zOutputNode.short_repr=  r   r   )r   r   rF   r'   rH   r   r~   r   s   @r   r   r   0  s!    *,R 

 9 9r   r   c                         e Zd Zd fd	Z xZS )r   c                 R    t         t        |   ||t        t        t
        h|       y )Nrw   )rn   r   r'   r   
GlobalNodeMergeOutputsNoder   s       r   r'   zOutputStream.__init__C  s+    lD*%56/	 	+ 	
r   r)   r   r   s   @r   r   r   B  s    
 
r   r   c                        e Zd Z fdZ xZS )r   c                 J    t         t        |   ||t        ht        dd        y )Nr   )rO   rq   rb   rr   r^   r_   )rn   r   r'   r   )r"   streamsrq   ru   s      r   r'   zMergeOutputsNode.__init__N  s,    .#/.!- 	/ 	
r   r   r   s   @r   r   r   M  s    
 
r   r   c                   $     e Zd Zg i f fd	Z xZS )r   c           
      N    t         t        |   ||t        ht        dd||       y r   )rn   r   r'   r   r   s        r   r'   zGlobalNode.__init__[  s1    j$(#/.!- 	) 		
r   r   r   s   @r   r   r   Z  s    *,R 

 

r   r   c                       fd}|S )Nc                 h    xs | j                   }D cg c]  }t        |||        c} | S c c}w r)   )r   setattr)func	func_namestream_classrq   stream_classess      r   	decoratorz"stream_operator.<locals>.decoratori  s3    )DMM	DRSLy$	/S 	Ts   /r@   )r   rq   r   s   `` r   stream_operatorr   h  s    
 r   c                 &    t        t        h|       S N)r   rq   )r   r   rq   s    r   filter_operatorr   q  s    +;*<4HHr   c                 &    t        t        h|       S r   )r   r   r   s    r   output_operatorr   u  s    <.tDDr   r)   )
__future__r   past.builtinsr   dagr   _utilsr   r   builtinsr	   r   r   r   r   rQ   rV   rX   rZ   r   r   r   r   r   r   r   r   r   r   __all__r@   r   r   <module>r      s    ' $  .  	PbV bJ	,
R+= R+j
v 
9 9*$5 $5P9 9$
6 
	
t 	

 
 %+8$ IE *r   