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
>Solution :
To print all available video resolutions for a YouTube video using PyTube, you can do the following:
- Include both progressive and adaptive streams.
- Use a set to store unique resolutions and filter out audio-only streams.
- 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.