Skip to main content

The PreTeXt Guide

Subsection 4.29.4 YouTube Videos

For a video hosted at YouTube, find the 11-character identification string in the address of a video you are viewing. It will look something like hAzdgU_kpGo. Then, instead of the @source attribute, simply provide this identification string as the @youtube attribute, such as
youtube="hAzdgU_kpGo"
That’s it. All of the options above are then implemented and realized with YouTube’s embedded player.
This can be a great way to incorporate popular or artistic content, legally, which might be difficult or costly to acquire through copyright clearance.
Figure 4.29.4.3. The Eagles, “Hotel California”
Figure 4.29.4.4. Mozart, Piano Sonata in C Major, K. 545, II
The pretext script (Chapter 47) may be used to download the provided preview images for YouTube videos (only). Filenames will be formed from the @xml:id of the <video> element. These will be used in static versions of output, such as print. Once custom preview images are implemented for author-hosted video, their static representation will improve.
Additionally, a YouTube playlist can be included in one of two ways. You may set the @youtube attribute to be a space-separated list of several video IDs (an “itemized” playlist). Alternatively, you may set the @youtubeplaylist attribute to a YouTube playlist ID (a “named” playlist). At present, a named playlist will not get a thumbnail image from Youtube, and either the “generic” thumbnail will be used or you can supply your own @preview.
Figure 4.29.4.5. YouTube Playlist
Make a feature-request if a scheme similar to the one for YouTube, but for some other video-hosting service, would be useful for your project.
Note that when a project is hosted at Runestone Academy (Chapter 32) a YouTube video becomes an activity that is part of a student’s reading assignement. So just like an interactive exercise, it needs a @label attribute. See Best Practice 4.12.0.26 for more.