Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 255
James Phoenix Avatar asked Oct 18 '25 16:10

James Phoenix


1 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
}
like image 96
James Phoenix Avatar answered Oct 21 '25 05:10

James Phoenix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!