Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I might want to get to the aftereffect of the accompanying shell command, 

youtube-dl -g ""

To print its yield direct URL to a document, from inside a python program. This is the thing that I have attempted: 

import youtube-dl



Is that conceivable? I attempted to comprehend the instrument in the source however got lost:

youtube_dl/, youtube_dl/, info_extractors ...

1 Answer

0 votes
by (26.4k points)

Check the below code:

import youtube_dl

ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s.%(ext)s'})

with ydl:

    result = ydl.extract_info(


        download=False # We just want to extract the info


if 'entries' in result:

    # Can be a playlist or a list of videos

    video = result['entries'][0]


    # Just a video

    video = result


video_url = video['url']


Wanna become a Python expert? Come and join the python certification course and get certified.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories