Callysto.ca Banner

Open in Callysto

Including YouTube videos

YouTube videos can be found online at https://www.youtube.com

When you find the video you want, click on the “share” button on the YouTube page, and you will get a web reference that looks something like this:

https://youtu.be/ZmhlRsYjs7Y

It is this last string of characters that you need.

In a code cell, you enter the commands

from IPython.display import YouTubeVideo
YouTubeVideo('ZmhlRsYjs7Y') 

Run the cell, and the video is ready to play!

(In this example below, we are using the Small Number videos from SFU.)

Example 1

Here is a sample YouTube video, loaded in from the internet. The code is

from IPython.display import YouTubeVideo
YouTubeVideo('ZmhlRsYjs7Y') ## Small Number video from SFU
from IPython.display import YouTubeVideo
YouTubeVideo('ZmhlRsYjs7Y') ## Small Number video from SFU

Example 2

Here is the same YouTube video, starting at 30 seconds in. We use the html magic to run this, which gives us more control. Note that we grabbed the code from the “Embed” option on the YouTube webpage, that gives the iframe commands with options.

%%html
<iframe width="300"  src="https://www.youtube.com/embed/ZmhlRsYjs7Y?start=30" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
%%html
<iframe width="300"  src="https://www.youtube.com/embed/ZmhlRsYjs7Y?start=30" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Callysto.ca License