
    g5%                     0   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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 dZdefdZ	 d!dededededeeef   f
dZy)"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    V/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/tools.pycross_platform_popen_paramsr	      s     $(2_%    c                    t        j                  |      } |ddj                  |       z          t        t        j
                  t        j                  t        j
                  d      }t	        j                  | fi |}|j                         \  }}|j                  j                          |j                  r# |d       t        |j                  d             |d       ~y)	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
-=>.::2::FL 88C(<(D!HCKK<=cjj())56r
   c                 2    | j                  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              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:

    .. 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              3   ,   K   | ]  \  }}||z    y wN ).0multparts      r   	<genexpr>z%convert_to_seconds.<locals>.<genexpr>a   s     JztTtd{Js   )

isinstancestrsplitfloatreplacetuplelistsumzipreversed)timefactorsr4   s      r   convert_to_secondsrB   @   ss    2 G$:>**S/J$dll3,-JJdUDM*JS(4.-IJJJ Ks   "Bc                 N      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   s'    kG+-FGT$V$$r
   )__name____doc__)rJ   old_namenew_namerL   rK   s   `   @r   deprecated_version_ofrQ   d   s1    4 }}H 
8	G% &Or
   video)libx264libmpeg4aac)typecodec	libtheoralibvpxrV   audio	libvorbis
libmp3lame)	pcm_s16le	pcm_s24le	pcm_s32le
libfdk_aac)
mp4mkv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      )zReturns the correspondent file extension for a codec.

    Parameters
    ----------

    codec : str
      Video or audio codec name.
    rW   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)rW   extinfoss      r   find_extensionrx      sY     %++- 
UEIIgr**J 	 r
   c                     ddl m} ddlm} ddlm} |||d| dk(  r
t               } t        | d      r| j                         } t        fd|D              }| D ]  }t        ||      s|j                          ! y	)
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)	ImageCliprZ   rR   rp   globalsvaluesc              3   (   K   | ]	  }|     y wr0   r1   )r2   key
CLIP_TYPESs     r   r5   z"close_all_clips.<locals>.<genexpr>   s     9C
39s   N)moviepy.audio.io.AudioFileCliprz   moviepy.video.io.VideoFileClipr{   moviepy.video.VideoClipr|   r~   hasattrr   r;   r6   r   )objectstypesrz   r{   r|   types_tupleobjr   s          @r   close_all_clipsr      sy    ( =<1 J ))w!.."9599K c;'IIKr
   returnc                      t        j                         } | dv r%dt        j                  vrdt        j                  vryd| v r%dt        j                  vrdt        j                  vryy)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      sZ     __FJJRZZ'.?rzz.QfRZZ'.?rzz.Qr
   
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        |      }|r2t        |      D ]$  \  }}t        ||   t              r|||   z  ||<   & t        |d   t              r&d|d   | d   z
  d	z  |d   | d   z
  d
}||d      |d<   t        |d   t              r&d|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`.
    )r   r   centerleftrighttopbottom)r   r   r   r   r   r      )r   r   r   r*   )r   r   r   )r6   r7   r<   	enumerateint)r   r   r   r   idimDs          r   compute_positionr      sY   4 { #s*X&x(e$*
  3i 
+ 	&FAsc!fc*s1vA	& #a&#!!}z!}49]Z]2

 3q6A#a&#!!}z!}49 mjm3

 3q6A AKSV%%r
   )bar)r~   r}   )F)rN   r   r   
subprocessr   rE   r   namer   r	   r#   r(   rB   rQ   rr   rv   rx   r   boolr   r;   anyr   r   r1   r
   r   <module>r      s   L 	     ''
4!KH(b &DE&DE{m4z2GG{m4|n5&MN|n5 1 -C"G,OC-0%Pd * FK@&@&#(@&/2@&>B@&
38_@&r
   