
    gx#                         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dZdez   dz   ddez   dz   dZ	 ddZ	 	 	 	 	 	 ddZy# e$ r d ZdZY 0w xY w)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y)HTML2c                 F    t        | j                  |j                  z         S N)r   data)selfothers     m/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/io/display_in_notebook.py__add__zHTML2.__add__   s    UZZ/00    N)__name__
__module____qualname__r    r   r   r   r      s    	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videoc                    |i }dt        | j                        v r&d}t        | t              r~|dz   }|dd}t	        j
                  | j                        j                  }	|j                  |j                         D 
ci c]  \  }
}|
|	v s|
| c}}
        | j                  d&i | nt        | t              r.|dz   }|dd	}|j                  |        | j                  d&i | nHt        | t              r-|d
z   }d|i}|j                  |        | j                  d&i | nt        d      t        |f|||d|S | }dj!                  |j                         D cg c]  \  }}t        |      dt        |      d! c}}      }t"        j$                  j'                  |      \  }}|dd }|J|j)                  d      d   j+                         }|dk(  rd}n |t,        v rt,        |   d   }nt        d      |dk(  r+dddd}dj!                  |j/                               }	 ||   }|dv r%t3        |d      d    }||kD  rt        d!||fz        t5        |d"      5 }t7        |j9                               j;                  d#      }ddd       t<        |   }|||d$z  }|rd%|z  }|S c c}}
w c c}}w # t0        $ r t        d|z         w xY w# 1 sw Y   KxY w)'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_maskz.mp4	ultrafast)r    presetz.mp3r    z5Unknown class for the clip. Cannot embed and preview.)maxduration	rd_kwargscenter z=''   .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   )str	__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    kwargsargnameskeyvaluekvr5   namer6   exts_htmltypeallowed_extsr3   filer   templateresults                           r   rC   rC   6   s+   d 	T^^$$ dI&"V+H"*>F--doo>CCHMM.7oo.?S
U3(?eS DOO%f%i("V+H"*kBFMM)$ D  *6*i("V+H (+FMM)$ D  *6*TUU
#	

 
 	
 HhhARARATUASVSV4UVG  *ID#
ab'CnnS!"%++-%<HO#&s+F3H0  7 !&veDxx 2 2 45	$C %%%hDA*Mk! X&'	 	 
h	 6%,,W56 "H'#FFF.7M] T2 V0  	9;GH 	(6 6s*    J3
J3
#$J9
-J? ')K?KK#c           
          t         st        d      |i }|||d<   || j                  |      } 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 Notebookfps)rQ   r$   r&   r%   )ipython_availableImportErrorto_ImageClipr   rC   )rP   rQ   r$   tra   r%   r&   rR   s           r   display_in_notebookrf      sv    H ABB	
	%}  #	
#	
 	
	 	r   )N<   NT)Nrg   NNNT)__doc__r:   rE   base64r   moviepy.audio.AudioClipr   moviepy.toolsr   moviepy.video.io.ffmpeg_readerr   moviepy.video.VideoClipr   r   IPython.displayr	   rb   r   rc   sorryrO   rC   rf   r   r   r   <module>rp      s     	  - ) = 8$1 1 	K	I
	 	
 J	=?D	EGQ	R	  AEJ^ 
YK   s   A# #
A0/A0