Ë
    Eü´j‡%  ã                   ó@  — 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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    úK/root/workspace/ytshorts/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ô �8‰8�CÑ(˜<Ñ(€Dà×ÑÓ!�H€CˆØ‡K�K×ÑÔà‡‚ÙÐ<Õ=Ü�c—j‘j Ó(Ó)Ð)áÐ5Õ6ár
   c                 ó2   — | j                  d«      rd| z   } | S )zŸEscape 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   è ø€ ÒJ™z˜t Tˆt�d�{ÑJùs   ‚)
Ú
isinstanceÚstrÚsplitÚfloatÚreplaceÚtupleÚlistÚsumÚzipÚreversed)ÚtimeÚfactorsr4   s      r   Úconvert_to_secondsrB   @   ss   € ð2 €Gä�$œÔØ:>¿*¹*ÀS»/ÖJ°$”�d—l‘l 3¨Ó,Õ-ÐJˆÐJä�dœU¤D˜MÔ*ØˆäÑJ¬S°¼(À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'   ø€ Ü�‰�k GÑ+Ô-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   rS   ÚproresÚaudioÚ	libvorbisÚ
libmp3lame)Ú	pcm_s16leÚ	pcm_s24leÚ	pcm_s32leÚ
libfdk_aacÚflac)Úmp4ÚmkvÚogvÚwebmÚaviÚmovÚoggÚmp3ÚwavÚm4arb   )ÚjpgÚjpegÚpngÚbmpÚtiffÚimagec                 ó”   — | t         v r| S t         j                  «       D ]  \  }}| |j                  dg «      v sŒ|c S  t        d«      ‚)z‹Returns the correspondent file extension for a codec.

    Parameters
    ----------

    codec : str
      Video or audio codec name.
    rW   z§The 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_extensionrz   ¦   sY   € ð ”Ñàˆä%×+Ñ+Ó-ò ‰
ˆˆUØ�E—I‘I˜g rÓ*Ò*ØŠ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©r[   rR   rr   ÚglobalsÚvaluesc              3   ó(   •K  — | ]	  }‰|   –— Œ y ­wr0   r1   )r2   ÚkeyÚ
CLIP_TYPESs     €r   r5   z"close_all_clips.<locals>.<genexpr>à   s   øè ø€ Ò9¨C˜
 3�Ñ9ùs   ƒN)Úmoviepy.audio.io.AudioFileClipr|   Úmoviepy.video.io.VideoFileClipr}   Úmoviepy.video.VideoClipr~   r€   Úhasattrr�   r;   r6   r   )ÚobjectsÚtypesr|   r}   r~   Útypes_tupleÚobjr„   s          @r   Úclose_all_clipsr�   ¾   sy   ø€ õ( =Ý<Ý1ð ØØñ€Jð �)ÒÜ“)ˆÜˆw˜Ô!Ø—.‘.Ó"ˆÜÓ9°5Ô9Ó9€KØò ˆÜ�c˜;Õ'Ø�I‰I�Kñ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ØœRŸZ™ZÑ'Ð.?ÄrÇzÁzÑ.QØà�fÑØœRŸZ™ZÑ'Ð.?ÄrÇzÁzÑ.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Ð$Ø Ð*ñ
ð ñ‰ô �3‹iˆñ Ü 
Ó+ò 	&‰FˆAˆsÜ˜c !™f¤cÕ*Ø˜s 1™v™��A’ð	&ô �#�a‘&œ#ÔàØ! !‘} z°!¡}Ñ4¸Ñ9Ø ‘] Z°¡]Ñ2ñ
ˆð
 �3�q‘6‘ˆˆA‰ä�#�a‘&œ#ÔàØ! !‘} z°!¡}Ñ4¸Ñ9Ø  ‘m j°¡mÑ3ñ
ˆð
 �3�q‘6‘ˆˆA‰ô ��A‘‹Kœ˜S ™V›Ð%Ð%r
   )Úbar)r€   r   )F)rN   r›   r™   Ú
subprocessr   rE   r   Únamer   r	   r#   r(   rB   rQ   rt   rx   rz   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ÐØ y°(Ð&;Ñ<Ø { mÑ4Ø | nÑ5ØÒ&MÑNØ | nÑ5Ø¨ xÑ0ñ€ð 1ò -€CØ" GÐ,€O�CÒð-òó0%ðP˜dó ð* FKñ@&Øð@&Ø#(ð@&Ø/2ð@&Ø>Bð@&à
ˆ3�ˆ8�_ô@&r
   