12

如果我将 youtube 视频剪辑嵌入到 iPython 笔记本中:

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

有没有办法可以嵌入它,让它从特定时间开始播放?所以 1:47:03 - 1 小时 47 分 3 秒?

4

1 回答 1

12

更新

现在您可以从 youtube 播放器中使用您喜欢的任何参数:

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")

旧答案

当前的实现不允许它,但它很容易扩展:

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)

瞧:

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

现在我们可以发送一个拉取请求:)

于 2012-10-29T11:48:54.793 回答