Back

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 "www.youtube.com/..."

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

fromurl="www.youtube.com/..."

geturl=youtube-dl.magiclyextracturlfromurl(fromurl)

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

youtube_dl/__init__.py, youtube_dl/youtube_DL.py, 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]

else:

    # Just a video

    video = result

print(video)

video_url = video['url']

print(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

...