"""
This module implements ipython_display
A function to embed images/videos/audio in the IPython Notebook
"""

# Notes:
# All media are physically embedded in the IPython Notebook
# (instead of simple links to the original files)
# That is because most browsers use a cache system and they won't
# properly refresh the media when the original files are changed.

import os
from base64 import b64encode
from moviepy.tools import extensions_dict

from ..VideoClip import VideoClip, ImageClip
from moviepy.audio.AudioClip import AudioClip

try:
    from IPython.display import HTML
    ipython_available = True
    class HTML2(HTML):
        def __add__(self, other):
            return HTML2(self.data+other.data)

except ImportError:
    ipython_available = False

from .ffmpeg_reader import ffmpeg_parse_infos

sorry = "Sorry, seems like your browser doesn't support HTML5 audio/video"
templates = {"audio":("<audio controls>"
                         "<source %(options)s  src='data:audio/%(ext)s;base64,%(data)s'>"
                     +sorry+"</audio>"),
             "image":"<img %(options)s "
                     "src='data:image/%(ext)s;base64,%(data)s'>",
             "video":("<video %(options)s"
                       "src='data:video/%(ext)s;base64,%(data)s' controls>"
                       +sorry+"</video>")}