Search code examples
pythonpytube

Pytube set Resolution


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?


Solution

  • 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()