Pytube set Resolution

Question:

I can download Videos with this code with Pytube:

from pytube import Youtube
Youtube('youryoutubelink').streams.first().download()

But when I open the Video, it is very low resolution. I want to have 720p/1080p.
How can I set this in my code?

Asked By: Saniii

||

Answers:

That’s because you are downloading the first one of the available streams which is usually 720p. To download a 360p resolution stream, you can do:

YouTube('https://youtu.be/2lAe1cqCOXo').streams.filter(res="360p").first().download()

Note: this is YouTube, not Youtube.

Short explanation:
You need to use filter() to choose a specific resolution you want to download. For example, if you call:

yt = YouTube('https://youtu.be/2lAe1cqCOXo')

it returns the available stream to yt. You can view all the streams by typing:

yt.streams

You can filter which type of filter you want. To filter only 360p streams you can write:

yt.streams.filter(res="360p")

To filter only 360p streams and download the first one type this:

yt.streams.filter(res="360p").first().download()
Answered By: Promit Basak

In this method you can download the available highest resolution video.

video = YouTube('mylink')
highresvid = video.streams.get_highest_resolution()
highresvid.download('location')
Answered By: Rovindu Thamuditha

Is it normal what YouTube(‘https://youtu.be/2lAe1cqCOXo’).streams.filter(res="720p").first().download()
gives me bad resolution?
YouTube(‘https://youtu.be/2lAe1cqCOXo’).streams.filter(abr="160kbps").first().download() gives me audio with 64kbps

Answered By: Ilia
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.