§
    7?Ä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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    ú>C:\Projects\Historical\venv\Lib\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õ Œ8�CÐ(Ð(˜<Ð(Ð(€Dà×ÒÑ!Ô!�H€CˆØ„K×ÒÑÔÐà„ð 7ØˆÐ<Ð=Ñ=Ô=Ð=Ý�c—j’j Ñ(Ô(Ñ)Ô)Ð)àˆÐ5Ð6Ñ6Ô6Ð6àˆˆr
   c                 ó:   — |                       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          ¦  «        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°$•�d—l’l 3¨Ñ,Ô,Ñ-Ô-Ð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ÐJ™z˜t Tˆt�d‰{Ð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ˆå�d�U¥D˜MÑ*Ô*ð ØˆåÐJÐJ­S°½(À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   ø€ ÝŒ�k GÑ+Õ-FÑGÔGÐGØˆt�TÐ$˜VÐ$Ð$Ð$r
   )Ú__name__Ú__doc__)rM   Úold_nameÚnew_namerO   rN   s   `   @r   Údeprecated_version_ofrT   d   sS   øø€ ð4 Œ}€H€Hð 
ˆˆ�8�8�8ð	€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¦  «        ‚)z‹Returns the correspondent file extension for a codec.

    Parameters
    ----------

    codec : str
      Video or audio codec name.
    rZ   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)rZ   ÚextÚinfoss      r   Úfind_extensionr}   ¦   sq   € ð •ÐÐàˆå%×+Ò+Ñ-Ô-ð ð ‰
ˆˆUØ�E—I’I˜g rÑ*Ô*Ð*Ð*ØˆJˆJˆJð +å
ð	ñô ð 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Ð9¨C˜
 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Ð9°5Ð9Ñ9Ô9Ñ9Ô9€KØð ð ˆÝ�c˜;Ñ'Ô'ð 	Ø�IŠI‰KŒKˆKøðð 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Ø�RœZÐ'Ð'Ð.?ÅrÄzÐ.QÐ.QØ�4à�fÐÐØ�RœZÐ'Ð'Ð.?ÅrÄzÐ.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Ð$Ø Ð*ð
ð 
ð ôˆˆõ �3‰iŒ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ŒK�˜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Ð,€O�CÑÐðð ð ð0%ð %ð %ð %ðP˜dð ð ð ð ð* FKð@&ð @&Øð@&Ø#(ð@&Ø/2ð@&Ø>Bð@&à
ˆ3�ˆ8„_ð@&ð @&ð @&ð @&ð @&ð @&r
   