'Get video from Youtube-DL is not working properly

I'm trying to get youtube video by using youtube_dl and everything is working fine except for the fact that I only get the audio.

from youtube_dl import YoutubeDL

link = "SOME_YOUTUBE_VIDEO" # as it was only a video

with YoutubeDL({}) as ydl:
    info = ydl.extract_info(link, download=False)
    url = info['formats'][0]['url']
    title = info["title"]
    print(url, title)


Solution 1:[1]

from youtube_dl import YoutubeDL

link = "https://www.youtube.com/watch?v=Y9wBC3H4iH4"

with YoutubeDL({}) as ydl:
    info = ydl.extract_info(link, download=False)
    for i, format in enumerate(info['formats']):
        print(f"[{i}] {format['format']}")

output:

[youtube] Y9wBC3H4iH4: Downloading webpage
[0] 249 - audio only (tiny)
[1] 250 - audio only (tiny)
[2] 251 - audio only (tiny)
[3] 140 - audio only (tiny)
[4] 160 - 256x144 (144p)
[5] 278 - 256x144 (144p)
[6] 242 - 426x240 (240p)
[7] 133 - 426x240 (240p)
[8] 243 - 640x360 (360p)
[9] 134 - 640x360 (360p)
[10] 244 - 854x480 (480p)
[11] 135 - 854x480 (480p)
[12] 247 - 1280x720 (720p)
[13] 136 - 1280x720 (720p)
[14] 248 - 1920x1080 (1080p)
[15] 137 - 1920x1080 (1080p)
[16] 18 - 640x360 (360p)
[17] 22 - 1280x720 (720p)

It literally says audio only for some of the formats! Select one of the non-audio-only formats, and you won't get audio only. Note that which formats are available very much depends on which video you're trying to download.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sören