§
    7?Äjx#  ã                   óð   — d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ 	 ddlmZ d	Z G d
„ de¦  «        Zn# e$ r d„ ZdZY nw xY wdZdez   dz   ddez   dz   dœZ	 dd„Z	 	 	 	 	 	 dd„ZdS )zeImplements ``display_in_notebook``, a function to embed images/videos/audio in the
Jupyter Notebook.
é    N)Ú	b64encode)Ú	AudioClip)Úextensions_dict)Úffmpeg_parse_infos)Ú	ImageClipÚ	VideoClip)ÚHTMLTc                   ó   — e Zd Zd„ ZdS )ÚHTML2c                 ó:   — t          | j        |j        z   ¦  «        S ©N)r   Údata)ÚselfÚothers     úUC:\Projects\Historical\venv\Lib\site-packages\moviepy/video/io/display_in_notebook.pyÚ__add__zHTML2.__add__   s   € Ý˜œ U¤ZÑ/Ñ0Ô0Ð0ó    N)Ú__name__Ú
__module__Ú__qualname__r   © r   r   r   r      s#   € € € € € ð	1ð 	1ð 	1ð 	1ð 	1r   r   c                 ó   — | S r   r   )Úcontents    r   r   r       s   € Øˆr   Fz@Sorry, seems like your browser doesn't support HTML5 audio/videozN<audio controls><source %(options)s  src='data:audio/%(ext)s;base64,%(data)s'>z</audio>z:<img %(options)s src='data:image/%(ext)s;base64,%(data)s'>zD<video %(options)ssrc='data:video/%(ext)s;base64,%(data)s' controls>z</video>)ÚaudioÚimageÚvideoé<   c                 ó   ‡— |€i }dt          | j        ¦  «        v �r#d}t          | t          ¦  «        ri|dz   }|ddœ}t	          j        | j        ¦  «        j        Š|                     ˆfd„| 	                    ¦   «         D ¦   «         ¦  «          | j        d&i |¤Ž n’t          | t          ¦  «        r-|dz   }|d	d
œ}|                     |¦  «          | j        d&i |¤Ž nPt          | t          ¦  «        r,|dz   }d|i}|                     |¦  «          | j        d&i |¤Ž nt          d¦  «        ‚t          |f|||dœ|¤ŽS | }d                     d„ | 	                    ¦   «         D ¦   «         ¦  «        }	t"          j                             |¦  «        \  }
}|dd…         }|€b|                     d¦  «        d                              ¦   «         }|dk    rd}n,|t,          v rt,          |         d         }nt          d¦  «        ‚|dk    rWddddœ}d                     |                     ¦   «         ¦  «        }	 ||         }n # t0          $ r t          d|z   ¦  «        ‚w xY w|dv r1t3          |d¬¦  «        d          }||k    rt          d!||fz  ¦  «        ‚t5          |d"¦  «        5 }t7          |                     ¦   «         ¦  «                             d#¦  «        }ddd¦  «         n# 1 swxY w Y   t<          |         }|||	|d$œz  }|rd%|z  }|S )'aï  Returns HTML5 code embedding the clip.

    Parameters
    ----------

    clip : moviepy.Clip.Clip
      Either a file name, or a clip to preview.
      Either an image, a sound or a video. Clips will actually be
      written to a file and embedded as if a filename was provided.

    filetype : str, optional
      One of 'video','image','audio'. If None is given, it is determined
      based on the extension of ``filename``, but this can bug.

    maxduration : float, optional
      An error will be raised if the clip's duration is more than the indicated
      value (in seconds), to avoid spoiling the browser's cache and the RAM.

    rd_kwargs : dict, optional
      Keyword arguments for the rendering, like ``dict(fps=15, bitrate="50k")``.
      Allow you to give some options to the render process. You can, for
      example, disable the logger bar passing ``dict(logger=None)``.

    center : bool, optional
      If true (default), the content will be wrapped in a
      ``<div align=middle>`` HTML container, so the content will be displayed
      at the center.

    html_kwargs
      Allow you to give some options, like ``width=260``, ``autoplay=True``,
      ``loop=1`` etc.

    Examples
    --------
    .. code:: python

        from moviepy import *
        # later ...
        html_embed(clip, width=360)
        html_embed(clip.audio)

        clip.write_gif("test.gif")
        html_embed('test.gif')

        clip.save_frame("first_frame.jpeg")
        html_embed("first_frame.jpeg")
    NÚClipÚ__temp__z.pngT)ÚfilenameÚ	with_maskc                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS r   r   )Ú.0ÚkeyÚvalueÚargnamess      €r   ú
<dictcomp>zhtml_embed.<locals>.<dictcomp>r   s$   ø€ ÐSÐSÐS¡
  UÀ3È(À?À?��eÀ?À?À?r   z.mp4Ú	ultrafast)r!   Úpresetz.mp3r!   z5Unknown class for the clip. Cannot embed and preview.)ÚmaxdurationÚ	rd_kwargsÚcenterú c                 óX   — g | ]'\  }}t          |¦  «        ›d t          |¦  «        ›d�‘Œ(S )z='ú')Ústr)r$   ÚkÚvs      r   ú
<listcomp>zhtml_embed.<locals>.<listcomp>‹   s5   € ÐUÐUÐU¹¸¸A¥S¨¡V¤V V V­S°©V¬V¨V¨VÐ4ÐUÐUÐUr   é   ú.éÿÿÿÿÚgifr   Útypez—No file type is known for the provided file. Please provide argument `filetype` (one of 'image', 'video', 'sound') to the display_in_notebook function.r   Úmp4ÚwebmÚogg)r:   r;   ÚogvzVThis video extension cannot be displayed in the Jupyter Notebook. Allowed extensions: )r   r   )Údecode_fileÚdurationzëThe duration of video %s (%.1f) exceeds the 'maxduration' attribute. You can increase 'maxduration', by passing 'maxduration' parameter to display_in_notebook function. But note that embedding large videos may take all the memory away!Úrbzutf-8)r   ÚoptionsÚextz<div align=middle>%s</div>r   )r1   Ú	__class__Ú
isinstancer   ÚinspectÚgetfullargspecÚ
save_frameÚargsÚupdateÚitemsr   Úwrite_videofiler   Úwrite_audiofileÚ
ValueErrorÚ
html_embedÚjoinÚosÚpathÚsplitextÚsplitÚlowerr   ÚkeysÚ	Exceptionr   Úopenr   ÚreadÚdecodeÚ	templates)ÚclipÚfiletyper+   r,   r-   Úhtml_kwargsÚTEMP_PREFIXr!   ÚkwargsrA   ÚnamerB   Úexts_htmltypeÚallowed_extsr?   Úfiler   ÚtemplateÚresultr'   s                      @r   rN   rN   6   s  ø€ ðd ÐØˆ	à•�T”^Ñ$Ô$Ð$Ñ$Ø ˆÝ�d�IÑ&Ô&ð 	VØ" VÑ+ˆHØ"*¸Ð>Ð>ˆFÝÔ-¨d¬oÑ>Ô>ÔCˆHØ�MŠMØSÐSÐSÐS¨i¯oªoÑ.?Ô.?ÐSÑSÔSñô ð ð ˆDŒOÐ%Ð%˜fÐ%Ð%Ð%Ð%Ý˜�iÑ(Ô(ð 	VØ" VÑ+ˆHØ"*°kÐBÐBˆFØ�MŠM˜)Ñ$Ô$Ð$Ø ˆDÔ Ð*Ð* 6Ð*Ð*Ð*Ð*Ý˜�iÑ(Ô(ð 	VØ" VÑ+ˆHØ  (Ð+ˆFØ�MŠM˜)Ñ$Ô$Ð$Ø ˆDÔ Ð*Ð* 6Ð*Ð*Ð*Ð*åÐTÑUÔUÐUåØð
à#ØØð	
ð 
ð
 ð
ð 
ð 	
ð €HØ�hŠhÐUÐUÀ×ARÒARÑATÔATÐUÑUÔUÑVÔV€GÝ”× Ò  Ñ*Ô*�I€Dˆ#Ø
ˆaˆbˆbŒ'€CàÐØ�nŠn˜SÑ!Ô! "Ô%×+Ò+Ñ-Ô-ˆØ�%Š<ˆ<ØˆHˆHØ•OÐ#Ð#Ý& sÔ+¨FÔ3ˆHˆHåð0ñô ð ð �7ÒÐð !&¨v¸eÐDÐDˆØ—x’x × 2Ò 2Ñ 4Ô 4Ñ5Ô5ˆð	Ø Ô$ˆCˆCøÝð 	ð 	ð 	Ýð9Ø;GñHñô ð ð	øøøð Ð%Ð%Ð%Ý% h¸DÐAÑAÔAÀ*ÔMˆØ�kÒ!Ð!Ýðð ˜XÐ&ñ'ñ	ô 	ð 	õ 
ˆh˜Ñ	Ô	ð 6 Ý˜Ÿš™œÑ%Ô%×,Ò,¨WÑ5Ô5ˆð6ð 6ð 6ñ 6ô 6ð 6ð 6ð 6ð 6ð 6ð 6øøøð 6ð 6ð 6ð 6õ ˜Ô"€Hà °'À#ÐFÐFÑF€FØð 8Ø.°Ñ7ˆà€Ms   È7I  É IÊ%5K&Ë&K*Ë-K*c           
      ó°   — t           st          d¦  «        ‚|€i }|�||d<   |�|                      |¦  «        } t          t	          | f||||dœ|¤Ž¦  «        S )aó  Displays clip content in an Jupyter Notebook.

    Remarks: If your browser doesn't support HTML5, this should warn you.
    If nothing is displayed, maybe your file or filename is wrong.
    Important: The media will be physically embedded in the notebook.

    Parameters
    ----------

    clip : moviepy.Clip.Clip
      Either the name of a file, or a clip to preview. The clip will actually
      be written to a file and embedded as if a filename was provided.

    filetype : str, optional
      One of ``"video"``, ``"image"`` or ``"audio"``. If None is given, it is
      determined based on the extension of ``filename``, but this can bug.

    maxduration : float, optional
      An error will be raised if the clip's duration is more than the indicated
      value (in seconds), to avoid spoiling the browser's cache and the RAM.

    t : float, optional
      If not None, only the frame at time t will be displayed in the notebook,
      instead of a video of the clip.

    fps : int, optional
      Enables to specify an fps, as required for clips whose fps is unknown.

    rd_kwargs : dict, optional
      Keyword arguments for the rendering, like ``dict(fps=15, bitrate="50k")``.
      Allow you to give some options to the render process. You can, for
      example, disable the logger bar passing ``dict(logger=None)``.

    center : bool, optional
      If true (default), the content will be wrapped in a
      ``<div align=middle>`` HTML container, so the content will be displayed
      at the center.

    kwargs
      Allow you to give some options, like ``width=260``, etc. When editing
      looping gifs, a good choice is ``loop=1, autoplay=1``.

    Examples
    --------

    .. code:: python

        from moviepy import *
        # later ...
        clip.display_in_notebook(width=360)
        clip.audio.display_in_notebook()

        clip.write_gif("test.gif")
        display_in_notebook('test.gif')

        clip.save_frame("first_frame.jpeg")
        display_in_notebook("first_frame.jpeg")
    z%Only works inside an Jupyter NotebookNÚfps)r\   r+   r-   r,   )Úipython_availableÚImportErrorÚto_ImageClipr   rN   )r[   r\   r+   Útrg   r,   r-   r]   s           r   Údisplay_in_notebookrl   Ã   s‘   € õH ð CÝÐAÑBÔBÐBàÐØˆ	à
€Øˆ	�%Ñà€}Ø× Ò  Ñ#Ô#ˆåÝØð	
àØ#ØØð	
ð 	
ð ð	
ð 	
ñ	ô 	ð 	r   )Nr   NT)Nr   NNNT)Ú__doc__rE   rP   Úbase64r   Úmoviepy.audio.AudioClipr   Úmoviepy.toolsr   Úmoviepy.video.io.ffmpeg_readerr   Úmoviepy.video.VideoClipr   r   ÚIPython.displayr	   rh   r   ri   ÚsorryrZ   rN   rl   r   r   r   ú<module>ru      sª  ððð ð €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð à -Ð -Ð -Ð -Ð -Ð -Ø )Ð )Ð )Ð )Ð )Ð )Ø =Ð =Ð =Ð =Ð =Ð =Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8ðØ$Ð$Ð$Ð$Ð$Ð$àÐð1ð 1ð 1ð 1ð 1�ñ 1ô 1ð 1ð 1øð ð ð ð ðð ð ð ÐÐÐðøøøð 	K€ð	Ià
ñ	ð ñ	ð
 Jð	=Ø?Dñ	EØGQñ	Rðð €	ð  AEðJð Jð Jð Jð^ ØØ
ØØØðYð Yð Yð Yð Yð Ys   ¬A Á
AÁA