Raj
Raj

Reputation: 69

How to select resolution as an input for a YouTube video using youtube_dl

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {}
url = input("Enter your URL:")
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    if
    ydl.download([url])
print("Downloaded!")

By default, it is downloading 360p videos. However, I want to download what is best resolution for that particular video. Could anyone help me? Thank you.

Upvotes: 0

Views: 1697

Answers (1)

Kumpelinus
Kumpelinus

Reputation: 660

Use the format option

If you want the best video format use bestvideo.

Example:

url = input("Enter your URL:")

ydl = youtube_dl.YoutubeDL({
    'outtmpl': '/tmp/testvideo.mp4',
    'format':' bestvideo+bestaudio'
})

ydl.download([url])

Edit: If you want to have the video and audio in 1 File, do:

'format':' bestvideo[ext=mp4]+bestaudio[ext=mp4]/mp4'

Instead of

'format':' bestvideo+bestaudio'

Upvotes: 2

Related Questions