如何设置 youtube-dl python 始终选择 1080p

How to set youtube-dl python to always pick 1080p

您好,我正在制作一个 python 脚本来使用 youtube-dl 从多个站点下载视频:

from __future__ import unicode_literals
import youtube_dl

downloadLinks = []

downloadLink = input('Link to download: ')
downloadLinks.append(downloadLink)

youtube_dl_options = {
    "outtmpl": "%(title)s-%(id)s.%(ext)s",
    "restrictfilenames": True,
    "nooverwrites": True,
    "writedescription": True,
    "writeinfojson": True,
    "writeannotations": True,
    "writethumbnail": True,
    "writesubtitles": True,
    "writeautomaticsub": True
}

with youtube_dl.YoutubeDL(youtube_dl_options) as ydl:
    ydl.download(downloadLinks)

问题是我想一直下载 1080p 版本的视频,但在某些情况下它只下载 720p(“最佳”)版本,我如何根据代码告诉 youtube-dl 下载仅 1080p。

在选项中我们需要这样设置格式:

youtube_dl_options = {
    "format": "mp4[height=1080]", # This will select the specific resolution typed here
    "outtmpl": "%(title)s-%(id)s.%(ext)s",
    "restrictfilenames": True,
    "nooverwrites": True,
    "writedescription": True,
    "writeinfojson": True,
    "writeannotations": True,
    "writethumbnail": True,
    "writesubtitles": True,
    "writeautomaticsub": True
}