Can I use yt-dlp to extract only one video info from a playlist?

Question:

Here’s my code using Python (simplified version):

import yt_dlp

YDL_OPTIONS = {
    'format': 'bestaudio*',
    'noplaylist': True,
}

with yt_dlp.YoutubeDL(YDL_OPTIONS) as ydl:
    info = ydl.extract_info(url, download=False)

The problem comes up when the url directs to a playlist
(e.g. https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb)

Here’s the output:

[youtube:tab] PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb: Downloading webpage
[youtube:tab] PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb: Downloading API JSON with unavailable videos
[download] Downloading playlist: C++
[youtube:tab] playlist C++: Downloading 100 videos
[download] Downloading video 1 of 100
[youtube] 18c3MTX0PK0: Downloading webpage
[youtube] 18c3MTX0PK0: Downloading android player API JSON
[download] Downloading video 2 of 100
[youtube] 1OsGXuNA5cc: Downloading webpage
[youtube] 1OsGXuNA5cc: Downloading android player API JSON
[download] Downloading video 3 of 100
[youtube] 1E_kBSka_ec: Downloading webpage
[youtube] 1E_kBSka_ec: Downloading android player API JSON
...

As you can see, the ‘noplaylist’ option didn’t work in this case.

Is there an option or function making ydl only extract one video info, for instance the first one, in the entire playlist?

Asked By: JeffreyRuan

||

Answers:

noplaylist: Download single video instead of a playlist if in doubt.

Source: github.com/yt-dlp/yt-dlp

What you shared with us isn’t a playlist of a single video so, according to me, there isn’t any doubt here.

You can request yt_dlp to treat only the first video of the playlist by adding 'playlist_items': '1' to YDL_OPTIONS. Then the info concerning the video are in info['entries'][0].

Answered By: Benjamin Loison
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.