从 Youtube-DL 获取视频无法正常工作

Get video from Youtube-DL is not working properly

我正在尝试使用 youtube_dl 获取 YouTube 视频,一切正常,除了我只能获取音频。

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)
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']}")

输出:

[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)

对于某些格式,字面意思是 audio only! Select non-audio-only 格式之一,您不会只获得音频。请注意,哪些格式可用在很大程度上取决于您要下载的视频。