Get video information from a list of playlist with youtube-dl

Viewed 11590

I'm tryng to get some informations from a list of playlists in youtube with youtube-dl. I've written this code but what it takes is not the video's informations but the playlist informations (e.g. the playlist title instead of the video title in the playlist). I can't understand why.

input_file = open("url")
for video in input_file:
    print(video)
ydl_opts = {
    'ignoreerrors': True
}
    with youtube_dl.YoutubeDL(ydl_opts) as ydl: 
                info_dict = ydl.extract_info(video, download=False)
                for i in info_dict:
                    video_thumbnail = info_dict.get("thumbnail"),
                    video_id = info_dict.get("id"),
                    video_title = info_dict.get("title"),
                    video_description = info_dict.get("description"),
                    video_duration = info_dict.get("duration")

Any help will be appreciated.

2 Answers

run the command

youtube-dl --print-json https://www.youtube.com/playlist?list=<playlist_id> > example.json

you can also uses the --get for retriving specific items for example

youtube-dl --get-title https://www.youtube.com/playlist?list=<playlist_id> > example.txt
Related