
    l0j                         d Z ddlZddlZddlZddlZddlZddlmZ d Z	d Z
dd	Zd
 Zd ZddZdg ddddgdddgdddiddiddgdddgddg ddddgdd	ZdD ]	Zddiee<   
d ZdS )zH
Misc. useful functions that can be used at many places in the program.
    N   )DEVNULLc                     t           j                            |            t           j                                         dS )z8 Writes and flushes without delay a text in the console N)sysstdoutwriteflush)ss    P/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/moviepy/tools.pysys_write_flushr      s4     JQJ    c                 ,    | rt          |           dS dS )z9 Only prints s (with sys_write_flush) if verbose is True.N)r   )verboser
   s     r   verbose_printr      s(      r   barTc                    t          j        |          } |d           t          t          j        t          d}t
          j        dk    rd|d<   t          j        | fi |}|                                \  }}|j	        
                                 |j        r0|r |d           t          |                    d                     |d	           ~d
S )zw Executes the given subprocess command.
    
    Set logger to None or a custom Proglog logger to avoid printings.
    z'Moviepy - Running:
>>> "+ " ".join(cmd))message)r   stderrstdinnti   creationflagsz#Moviepy - Command returned an errorutf8zMoviepy - Command successfulN)proglogdefault_bar_loggerr   spPIPEosnamePopencommunicater   close
returncodeIOErrordecode)cmdlogger
errorprintpopen_paramsprocouterrs          r   subprocess_callr,      s    
 '//F
F=>>>>% g$& &L 
w$(2_%8C((<((D!!HCK 7 	BF@AAAAcjj(()))56666r   c                 x    	 t          | t                    S # t          $ r t          | t                    cY S w xY w)z^ Returns true if s is string or string-like object,
    compatible with Python 2 and Python 3.)
isinstance
basestring	NameErrorstr)objs    r   	is_stringr3   <   sH    $#z*** $ $ $#s#####$s    99c           	         d}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::

    >>> cvsecs(15.4)   # seconds 
    15.4 
    >>> cvsecs((1, 21.5))   # (min,sec) 
    81.5 
    >>> cvsecs((1, 1, 2))   # (hr, min, sec)  
    3662  
    >>> cvsecs('01:01:33.045') 
    3693.045
    >>> cvsecs('01:01:33,5')    # coma works too
    3693.5
    >>> cvsecs('1:33,5')    # only minutes and secs
    99.5
    >>> cvsecs('33.5')      # only secs
    33.5
    )r   <   i  c                 T    g | ]%}t          |                    d d                    &S ),.)floatreplace).0fs     r   
<listcomp>zcvsecs.<locals>.<listcomp>_   s.    DDDqaiiS))**DDDr   :c              3   &   K   | ]\  }}||z  V  d S N )r;   multparts      r   	<genexpr>zcvsecs.<locals>.<genexpr>d   s*      JJztTtd{JJJJJJr   )r3   splitr.   tuplelistsumzipreversed)timefactorss     r   cvsecsrM   E   s}    . G EDDDJJsOODDDdUDM** JJS(4..-I-IJJJJJJr   c                 H     | j         }d|d|d fd}|_        |S )a   Indicates that a function is deprecated and has a new name.

    `f` is the new function, `oldname` the name of the deprecated
    function, `newname` the name of `f`, which can be automatically
    found.

    Returns
    ========

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

    Examples
    =========

    >>> # 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')
    Nz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)akwr<   warnings     r   fdeprz$deprecated_version_of.<locals>.fdepr   s-    kG+-FGGGq!{r{{r   )__name____doc__)r<   oldnamenewnamerV   rU   s   `   @r   deprecated_version_ofr[   g   sT    4 !* $+77GGG5G      EMLr   video)libx264libmpeg4aac)typecodec	libtheoralibvpxr`   audio	libvorbis
libmp3lame)	pcm_s16le	pcm_s24le	pcm_s32le
libfdk_aac)	mp4ogvwebmavimovoggmp3wavm4a)jpgjpegpngbmptiffimagec                     | t           v r| S t                                           D ]!\  }}| |                    dg           v r|c S "t          d          )Nra   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)ra   extinfoss      r   find_extensionr      so    $**,,  	EEIIgr****JJJ +
	  r   )r   Tr@   )rX   r   
subprocessr   r   rP   r   compatr   r   r   r,   r3   rM   r[   r{   r   r   rA   r   r   <module>r      s{    
			     



               :$ $ $K K KD% % % %Z %,5R5R5RSS$+k]CC$+hZ@@#G,#G,$+k]CC$+l^DD$+5\5\5\]]$+l^DD
 
 1 , ,C"7+OC    r   