
    i                         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y)zH
Misc. useful functions that can be used at many places in the program.
    N   )DEVNULLc                 ~    t         j                  j                  |        t         j                  j                          y)z8 Writes and flushes without delay a text in the console N)sysstdoutwriteflush)ss    K/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/moviepy/tools.pysys_write_flushr      s&     JJQJJ    c                      | rt        |       yy)z9 Only prints s (with sys_write_flush) if verbose is True.N)r   )verboser
   s     r   verbose_printr      s     r   c                    t        j                  |      } |d       t        t        j                  t        d}t
        j                  dk(  rd|d<   t        j                  | fi |}|j                         \  }}|j                  j                          |j                  r%|r	 |d       t        |j                  d             |d	       ~y
)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
=>% gg$&L 
ww$(2_%88C(<(D!HCKK@Acjj())56r   c                 b    	 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_stringr2   <   s0    $#z** $#s##$s    ..c           	         d}t        |       r7| j                  d      D cg c]  }t        |j                  dd             } }t	        | t
        t        f      s| S t        d t        |t        |             D              S c c}w )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              3   ,   K   | ]  \  }}||z    y wN ).0multparts      r   	<genexpr>zcvsecs.<locals>.<genexpr>d   s     JztTtd{Js   )
r2   splitfloatreplacer-   tuplelistsumzipreversed)timefactorsfs      r   cvsecsrJ   E   sp    . G48JJsODqaiiS)*DDdUDM*JS(4.-IJJJ Es   "Bc                 R     | 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')
    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)akwrI   warnings     r   fdeprz$deprecated_version_of.<locals>.fdepr   s%    kG+-FG!{r{r   )__name____doc__)rI   oldnamenewnamerS   rR   s   `   @r   deprecated_version_ofrX   g   s4    4 !** $+G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         j                         D ]  \  }}| |j                  dg       v s|c S  t        d      )Nr^   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)r^   extinfoss      r   find_extensionr~      sW    $**, 	EEIIgr**J 	 r   )barTr9   )rU   r   
subprocessr   r   rM   r   compatr   r   r   r+   r2   rJ   rX   rx   r|   r~   r:   r   r   <module>r      s    
  
   :$KD%Z %,5RS$+k]C$+hZ@#G,#G,$+k]C$+l^D$+5\]$+l^D
 1 ,C"7+OC,r   