How to extract/read data from a (youtube) stream object?

Viewed 27

Below is my code:

from pytube import YouTube
url = 'https://www.youtube.com/watch?v=r-uOLxNrNk8'
video = YouTube(url).streams.get_highest_resolution()

I am trying to get a youtube video using pytube, using which I am trying to extract the filesize.

The variable video is of type <class 'pytube.streams.Stream'>, and contains multiple attributes of the video. I want to understand, how to extract/read this data (filesize, resolution, etc).

1 Answers

Got the answer.

To extract filesize, we just need to do use <stream>.filesize:

from pytube import YouTube
url = 'https://www.youtube.com/watch?v=r-uOLxNrNk8'
video = YouTube(url).streams.get_highest_resolution()
print(video.filesize)
Related