Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the ipython notebook YouTubeVideo class play from time offset

If I am embedding a youtube video clip into an iPython notebook:

from IPython.display import YouTubeVideo
YouTubeVideo("Pi9NpxAvYSs")

Is there a way I can embed this such that it would play from a specific time? So 1:47:03 - 1 hour, 47 minutes and 3 seconds?

like image 599
Danny Staple Avatar asked Oct 29 '12 10:10

Danny Staple


People also ask

Can we play video in Jupyter Notebook?

How do you view videos on a Jupyter Notebook? To display local video files in the Jupyter notebook, we should use an Html video tag ( <video ), and set the base64 encoded video file content to the src attribute of the Html video tag ( <video .. src='data:video/x-m4v;base64, ' ).

Is Jupyter Notebook same as IPython?

The IPython Notebook is now known as the Jupyter Notebook. It is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media. For more details on the Jupyter Notebook, please see the Jupyter website.


1 Answers

Update

Now you can use any parameter you like from the youtube player:

from datetime import timedelta

start=int(timedelta(hours=1, minutes=46, seconds=40).total_seconds())

YouTubeVideo("Pi9NpxAvYSs", start=start, autoplay=1, theme="light", color="red")

Old answer

The current implementation doesn't allow it, but it's pretty easy to extend:

from datetime import timedelta

class YouTubeVideo(object):
    def __init__(self, id, width=400, height=300, start=timedelta()):
        self.id = id
        self.width = width
        self.height = height
        self.start = start.total_seconds()

    def _repr_html_(self):
        return """
            <iframe
                width="%i"
                height="%i"
                src="http://www.youtube.com/embed/%s?start=%i"
                frameborder="0"
                allowfullscreen
            ></iframe>
        """%(self.width, self.height, self.id, self.start)

And voilà:

YouTubeVideo("Pi9NpxAvYSs", start=timedelta(hours=1, minutes=47, seconds=3))

Now we could send a pull request :)

like image 102
Paolo Moretti Avatar answered Nov 07 '22 06:11

Paolo Moretti