Search code examples
pythonpytube

Fetch youtube video resolution in python pytube


I am trying to make a youtube video downloader using pytube. So, I need different video resolution which is available for this video(example: 360p, 480p, 720p...)

my code is given bellow:

from pytube import YouTube
yt = YouTube("https://youtu.be/xyzxyzxyz")
print(yt.streams[0])

output:

<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">

data type of this output is:

<class 'pytube.streams.Stream'>

now I want to fetch this (res="360p") separately.

how can I do it?


Solution

  • You might want to try this:

    from pytube import YouTube
    yt = YouTube("https://www.youtube.com/watch?t=27&v=RjLH2vE5rpk")
    print(yt.streams.get_highest_resolution().resolution)
    

    Output:

    360p