
    -ix#                         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     b/var/www/html/speakWrite/venv/lib/python3.11/site-packages/moviepy/video/io/display_in_notebook.py__add__zHTML2.__add__   s    UZ/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 | nt          | 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
U3(??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ASVVVVSVVVV4UUUr      .gifr   typezNo 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durationzThe 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^$$$$ dI&& 	V"V+H"*>>F-do>>CHMMSSSSioo.?.?SSS   DO%%f%%%%i(( 	V"V+H"*kBBFMM)$$$ D **6****i(( 	V"V+H (+FMM)$$$ D **6****TUUU
#	
 

 
 
 	
 HhhUUARARATATUUUVVG  **ID#
abb'CnnS!!"%++--%<<HHO##&s+F3HH0   7 !&veDDxx 2 2 4 455	$CC 	 	 	9;GH  	 %%%%hD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FF 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