Using Playlists

This guide will walk you through the basics of working with pytube Playlists.

Creating a Playlist

Using pytube to interact with playlists is very simple. Begin by importing the Playlist class:

>>> from pytube import Playlist

Now let’s create a playlist object. You can do this by initializing the object with a playlist URL:

>>> p = Playlist('')

Or you can create one from a video link in a playlist:

>>> p = Playlist('')

Now, we have a Playlist object called p that we can do some work with.

Interacting with a playlist

Fundamentally, a Playlist object is just a container for YouTube objects.

If, for example, we wanted to download all of the videos in a playlist, we would do the following:

>>> print(f'Downloading: {p.title}')
Downloading: Python Tutorial for Beginers (For Absolute Beginners)
>>> for video in p.videos:
>>>     video.streams.first().download()

Or, if we’re only interested in the URLs for the videos, we can look at those as well:

>>> for url in p.video_urls[:3]:
>>>     print(url)

And that’s basically all there is to it!