How to set youtube-dl Python to always pick 1080p?

Question:

I’m making a Python script to download videos from multiple sites using 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)

Well the problem is I want to download always the 1080p version of the video, but in some cases it only download the 720p ("best") version, how I can based on code tell to youtube-dl to download the 1080p only.

Asked By: James Phoenix

||

Answers:

in the options we need to put the format like this:

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
}
Answered By: James Phoenix

"best" is the best quality combination of video and audio; specifying only the video resolution may not work. You need to put the audio format like this

'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best'
Answered By: Jin I
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.