Skip to content Skip to sidebar Skip to footer

How Do I Retrieve Individual Video Urls From A Playlist, Using Youtube-dl Within A Python Script?

I'm trying to: Use youtube-dl within a Python script to download videos periodically Organize/name the videos dynamically by youtube data i.e. %(title)s Extract audio/MP3 and move

Solution 1:

I'm working on cleaning this up so more, but I discovered the answer in a section of another answer...

To get individual links from a playlist url:

ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s', 'quiet':True,})
video = ""with ydl:
    result = ydl.extract_info \
    (yt_url,
    download=False) #We just want to extract the infoif'entries'in result:
        # Can be a playlist or a list of videos
        video = result['entries']

        #loops entries to grab each video_urlfor i, item inenumerate(video):
            video = result['entries'][i]

the youtube_dl.YoutubeDL seems to return JSON data from the YouTube API yt_url is a variable for either a video or playlist.

If the returned data has "entries" it's a playlist - then I loop those each entry (enumerate entries with i(ndex)) -- from there I can do what I want with the urls or other info.

result['entries'][i]['webpage_url']#urlofvideoresult['entries'][i]['title']#titleofvideoresult['entries'][i]['uploader']#usernameofuploaderresult['entries'][i]['playlist']#nameoftheplaylistresult['entries'][i]['playlist_index']#ordernumberofvideo

Post a Comment for "How Do I Retrieve Individual Video Urls From A Playlist, Using Youtube-dl Within A Python Script?"