📂 Stop downloading course lectures 1-by-1 — grab the whole playlist


Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python.

Think about the time you waste right-clicking and saving course lectures on YouTube one-by-one. Inefficient process, can cause errors and you lose focus. pytubefix eliminates that bottleneck.

Today is day 3 of mastering YouTube with Python. You already know how to get stats of a single video; or download them in various formats. Now time to level up with playlists.

Pytubefix has a Playlist object that provides methods to interact with all videos inside a YouTube playlist simultaneously.

Here we go...

📦 Import relevant libraries. Assign playlist url to Playlist object

In:
from pytubefix import YouTube, Playlist
pl = Playlist("https://www.youtube.com/playlist?list=PLRdw3IjKY2glTEYlhXRQ4hT5vksrU5UFt")
Out:

📌 Number of videos in the playlist

In:
total = len(pl.video_urls)
print(total)
Out: 16

👉 Get links of all videos in the playlist

Have print only 3 for simplicity

In:
for video_url in pl.video_urls:
    print(video_url)
Out:
https://www.youtube.com/watch?v=9m9tmIImmDg
https://www.youtube.com/watch?v=vZvQn5Tl_uo
https://www.youtube.com/watch?v=r4vbGBxsLyM

💾 Download first video

In:
yt = YouTube(pl.video_urls[0])
yt.streams.get_highest_resolution().download()
Out: '~\Minnesota Vikings vs Pittsburgh Steelers Week 4 Game Preview.mp4'

🔤 Check if captions are available

In:
yt = YouTube(pl.video_urls[0])
print(yt.captions.keys())
Out: KeysView({'a.en': Caption lang="English (auto-generated)" code="a.en">})

🚩 Read caption (first few words)

In:
caption = yt.captions["a.en"]
print(caption.generate_srt_captions()[:200])
Out:
1
00:00:00,400 --> 00:00:05,120
Trust the moment, man. Be in the moment.
2
00:00:02,560 --> 00:00:07,839
Play after play after play. We some dog.

📝 Check video description

In: print(yt.description[:200])
Out: Watch live local and primetime games, NFL RedZone, and NFL Network on Plus.NFL.com
Check out our other channels:

🖼️ Thumbnail link (if you want to download)

In: print(yt.thumbnail_url)
Out: https://i.ytimg.com/vi/VIDEO_ID/maxresdefault.jpg

🙌 Finally! Download all videos at once (highest resolution)

In:
for url in pl.video_urls:
    yt = YouTube(url)
    yt.streams.get_highest_resolution().download()
Out:

⭐📣 That's it for today! If you liked it, please share it with anyone who will find it useful and share your feedback below 🐼

Pandas Daily

Beginner to Expert in Python in just 5 minutes

Read more from Pandas Daily

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. You have a spreadsheet with 500 numbers. Your boss asks: "What do you see?" Most will freeze, scroll, guess. Not you! 3 Python functions to turn raw numbers into answers. No calculator, excel sheets. Just code. Statistics isn't boring math. It's how you make decisions with data. Using just the statistics module we find "center" of any dataset. Any data analyst must know the basics‼️ 🎯 Compute simple...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Last week we introduced numpy. Created bunch of arrays, sliced them and did some math with them. To prepare data for machine learning or any analysis, we need to learn to control their shape. Today - Reshape flat lists into grids. Flatten 2D tables back to 1D arrays. Create arrays filled with zeros, ones, or random numbers. ⏪ Recap: See dimensions first In: import numpy as np sales = np.array([120, 340,...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. TGIF! Everyone is talking about AI. Most people take courses. You're going to build it instead. Let's create a simple sentiment analyzer that reads customer reviews and classifies them as positive or negative. No machine learning libraries—just Python. 🎯 Define list of positive and negative words In: positive_words = ["good", "great", "excellent", "amazing", "love", "best"] negative_words = ["bad",...