
    -i%                     :   d Z ddlZddlZddlZddlZddlZej        Zd Z	d&dZ
d Zd Zd Zd	g d
dd	g d
dd	dgdd	dgddd	id	ddgdddgdddgddg ddddgdddgddZdD ]	Zddiee<   
d Zd'dZdefdZ	 d(d!ed"ed#ed$edeeef         f
d%ZdS ))zFMisc. useful functions that can be used at many places in the program.    Nc                 &    t           dk    rd| d<   | S )aX  Wrap with this function a dictionary of ``subprocess.Popen`` kwargs and
    will be ready to work without unexpected behaviours in any platform.
    Currently, the implementation will add to them:

    - ``creationflags=0x08000000``: no extra unwanted window opens on Windows
      when the child process is created. Only added on Windows.
    nti   creationflags)OS_NAME)popen_paramss    K/var/www/html/speakWrite/venv/lib/python3.11/site-packages/moviepy/tools.pycross_platform_popen_paramsr	      s     $(2_%    barc                    t          j        |          } |dd                    |           z              t          t          j        t          j        t          j        d          }t	          j        | fi |}|                                \  }}|j	        
                                 |j        r. |d           t          |                    d                     |d           ~dS )	zrExecutes the given subprocess command.

    Set logger to None or a custom Proglog logger to avoid printings.
    zMoviePy - Running:
>>>  )message)stdoutstderrstdinz#MoviePy - Command returned an errorutf8zMoviePy - Command successfulN)proglogdefault_bar_loggerjoinr	   spDEVNULLPIPEPopencommunicater   close
returncodeIOErrordecode)cmdloggerr   procouterrs         r   subprocess_callr$      s    
 '//F
F-=>>>>.:2:FF L 8C((<((D!!HCK 7<====cjj(()))56666r
   c                 :    |                      d          rd| z   } | S )zEscape a filename that we want to pass to the ffmpeg command line

    That will ensure the filename doesn't start with a '-' (which would raise an error)
    -z./)
startswith)filenames    r   ffmpeg_escape_filenamer)   5   s(    
 3 #(?Or
   c           	         d}t          | t                    rd |                     d          D             } t          | t          t          f          s| S t          d t          |t          |                     D                       S )a|  Will convert any time into seconds.

    If the type of `time` is not valid,
    it's returned as is.

    Here are the accepted formats:

    .. code:: python

        convert_to_seconds(15.4)   # seconds
        15.4
        convert_to_seconds((1, 21.5))   # (min,sec)
        81.5
        convert_to_seconds((1, 1, 2))   # (hr, min, sec)
        3662
        convert_to_seconds('01:01:33.045')
        3693.045
        convert_to_seconds('01:01:33,5')    # coma works too
        3693.5
        convert_to_seconds('1:33,5')    # only minutes and secs
        99.5
        convert_to_seconds('33.5')      # only secs
        33.5
    )   <   i  c                 T    g | ]%}t          |                    d d                    &S ),.)floatreplace).0parts     r   
<listcomp>z&convert_to_seconds.<locals>.<listcomp>\   s.    JJJ$dll3,,--JJJr
   :c              3   &   K   | ]\  }}||z  V  d S N )r2   multr3   s      r   	<genexpr>z%convert_to_seconds.<locals>.<genexpr>a   s*      JJztTtd{JJJJJJr
   )
isinstancestrsplittuplelistsumzipreversed)timefactorss     r   convert_to_secondsrE   @   s    2 G$ KJJ$**S//JJJdUDM** JJS(4..-I-IJJJJJJr
   c                 D      j         }d|d|d fd}|_        |S )a  Indicates that a function is deprecated and has a new name.

    `func` is the new function and `old_name` is the name of the deprecated
    function.

    Returns
    -------

    deprecated_func
      A function that does the same thing as `func`, but with a docstring
      and a printed message on call which say that the function is
      deprecated and that you should use `func` instead.

    Examples
    --------

    .. code:: python

        # The badly named method 'to_file' is replaced by 'write_file'
        class Clip:
            def write_file(self, some args):
                # blablabla
        Clip.to_file = deprecated_version_of(Clip.write_file, 'to_file')
    zThe function ``za`` is deprecated and is kept temporarily for backwards compatibility.
Please use the new name, ``z``, instead.c                  N    t          j        dz   t                      | i |S )Nz	MoviePy: )warningswarnPendingDeprecationWarning)argskwargsfuncwarnings     r   deprecated_funcz.deprecated_version_of.<locals>.deprecated_func   s0    kG+-FGGGtT$V$$$r
   )__name____doc__)rM   old_namenew_namerO   rN   s   `   @r   deprecated_version_ofrT   d   sS    4 }HH 
888	G% % % % % % &Or
   video)libx264libmpeg4aac)typecodec	libtheoralibvpxrY   rV   proresaudio	libvorbis
libmp3lame)	pcm_s16le	pcm_s24le	pcm_s32le
libfdk_aacflac)mp4mkvogvwebmavimovoggmp3wavm4are   )jpgjpegpngbmptiffimagec                     | t           v r| S t                                           D ]!\  }}| |                    dg           v r|c S "t          d          )zReturns the correspondent file extension for a codec.

    Parameters
    ----------

    codec : str
      Video or audio codec name.
    rZ   zThe audio_codec you chose is unknown by MoviePy. You should report this. In the meantime, you can specify a temp_audiofile with the right extension in write_videofile.)extensions_dictitemsget
ValueError)rZ   extinfoss      r   find_extensionr}      sq     %++--  
UEIIgr****JJJ +
	  r
   globalsr^   rU   ru   c                 0   ddl m} ddlm} ddlm} |||d| dk    rt                      } t          | d          r|                                 } t          fd|D                       }| D ]&}t          ||          r|                                 'd	S )
a  Closes all clips in a context.

    Follows different strategies retrieving the namespace from which the clips
    to close will be retrieved depending on the ``objects`` argument, and filtering
    by type of clips depending on the ``types`` argument.

    Parameters
    ----------

    objects : str or dict, optional
      - If is a string an the value is ``"globals"``, will close all the clips
        contained by the ``globals()`` namespace.
      - If is a dictionary, the values of the dictionary could be clips to close,
        useful if you want to use ``locals()``.

    types : Iterable, optional
      Set of types of clips to close, being "audio", "video" or "image" the supported
      values.
    r   )AudioFileClip)VideoFileClip)	ImageClipr   r~   valuesc              3   (   K   | ]}|         V  d S r7   r8   )r2   key
CLIP_TYPESs     r   r:   z"close_all_clips.<locals>.<genexpr>   s'      99C
3999999r
   N)moviepy.audio.io.AudioFileClipr   moviepy.video.io.VideoFileClipr   moviepy.video.VideoClipr   r~   hasattrr   r>   r;   r   )objectstypesr   r   r   types_tupleobjr   s          @r   close_all_clipsr      s    ( =<<<<<<<<<<<111111  J )))w!! #..""9999599999K  c;'' 	IIKKK r
   returnc                      t          j                    } | dv rdt          j        vrdt          j        vrdS d| v rdt          j        vrdt          j        vrdS dS )a!  Return True if we determine the host system has no graphical environment.
    This is usefull to remove tests requiring display, like preview

    ..info::
        Currently this only works for Linux/BSD systems with X11 or wayland.
        It probably works for SunOS, AIX and CYGWIN
    )LinuxFreeBSDNetBSDOpenBSDSunOSAIXDISPLAYWAYLAND_DISPLAYT	CYGWIN_NTF)platformsystemosenviron)r   s    r   no_display_availabler      sk     _FJJJRZ''.?rz.Q.Q4fRZ''.?rz.Q.Q45r
   F
clip1_size
clip2_sizeposrelativec                    |d}t          |t                    rddgddgddgddgddgd|         }nt          |          }|r>t          |          D ].\  }}t          ||         t                    s|||         z  ||<   /t          |d	         t                    r8d	|d	         | d	         z
  d
z  |d	         | d	         z
  d}||d	                  |d	<   t          |d         t                    r8d	|d         | d         z
  d
z  |d         | d         z
  d}||d                  |d<   t	          |d	                   t	          |d                   fS )a  Return the position to put clip 1 on clip 2 based on both clip size
    and the position of clip 1, as return by clip1.pos() method

    Parameters
    ----------
    clip1_size : tuple
        The width and height of clip1 (e.g., (width, height)).
    clip2_size : tuple
        The width and height of clip2 (e.g., (width, height)).
    pos : Any
        The position of clip1 as returned by the `clip1.pos()` method.
    relative: bool
        Is the position relative (% of clip size), default False.

    Returns
    -------
    tuple[int, int]
        A tuple (x, y) representing the top-left corner of clip1 relative to clip2.

    Notes
    -----
    For more information on `pos`, see the documentation for `VideoClip.with_position`.
    N)r   r   centerleftrighttopbottom)r   r   r   r   r   r      )r   r   r   r+   )r   r   r   )r;   r<   r?   	enumerateint)r   r   r   r   idimDs          r   compute_positionr      s   4 { #s 	*X&x(e$*
 
  3ii  &
++ 	& 	&FAsc!fc** &s1vA#a&# !!}z!}49]Z]2
 

 3q6A#a&# !!}z!}49 mjm3
 

 3q6A AKKSV%%r
   )r   )r~   r   )F)rQ   r   r   
subprocessr   rH   r   namer   r	   r$   r)   rE   rT   rw   r{   r}   r   boolr   r>   anyr   r   r8   r
   r   <module>r      s   L L 				        '
 
 
   4  !K !K !KH( ( (b &D&D&DEE&D&D&DEE{m44z22Gy(&;<<{m44|n55&M&M&MNN|n55x00  1 - -C"G,OC  0% % % %Pd    * FK@& @&@&#(@&/2@&>B@&
38_@& @& @& @& @& @&r
   