Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PyTube printing video resolutions

Is there a way to print all the video resolutions clearly

from pytube import YouTube

# enter video URL
video_url = ""

# create youtube thing
yt = YouTube(video_url)

# Get list of all resolutions
resolutions = []
for stream in yt.streams.filter(progressive=True):
    resolutions.append(stream.resolution)

# sort resolutions and print
resolutions.sort()
print("Available Resolutions: ")
for res in resolutions:
    print(res)

Output for this code:

Available Resolutions: 
144p
360p
720p

but there is more resolutions why cant i see and i want to print all of them clear like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To print all available video resolutions for a YouTube video using PyTube, you can do the following:

  1. Include both progressive and adaptive streams.
  2. Use a set to store unique resolutions and filter out audio-only streams.
  3. Sort and print the resolutions.

Here’s the code:

from pytube import YouTube

video_url = "https://www.youtube.com/watch?v=RbmS3tQJ7Os"  # Enter the video URL

yt = YouTube(video_url)
resolutions = sorted(
    {stream.resolution for stream in yt.streams if stream.resolution},
    key=lambda x: int(x[:-1]),
)

print("Available Resolutions:")
for res in resolutions:
    print(res)

You can change my video ("https://www.youtube.com/watch?v=RbmS3tQJ7Os") with any video you like.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading