0

I'm programming a youtube video downloader that allows you to download youtube videos in different resolutions and refresh rates. However, when I try to list the available resolutions and fps, I weirdly only get lower quality options. In my code example I am using the YouTube Rewind 2019 video that is used for an example in the docs. Here is my code:

from pytube import YouTube

youtube = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')

for stream in youtube.streams.filter(progressive=True):
    print("resolution: " + stream.resolution)
    print("fps: " + str(stream.fps))
    print("----------------------")

and here is my output:

/mnt/d/youtube-downloader$ python3 main.py
resolution: 360p
fps: 24
----------------------
resolution: 720p
fps: 24
----------------------

As you can see the only qualities I get are 720p and 360p although the youtube video used can scale all the way up to 1080p. Is there a different function I should be aware of.

I've also found a closed GitHub issue which seems to be similar to mine but doesn't have an answer I can work with which is why I've posted this issue here.

Thanks for your time.

Faizan Shah
  • 59
  • 1
  • 9

4 Answers4

1

I've just gone through the same issue. You can use something like this

from pytube import YouTube
import os

youtube = YouTube('https://youtu.be/kdmgpMfnjdU')
video = youtube.streams.filter(res="480p").first().download()
os.rename(video,"video_best.mp4")

Notice that 480p is the best available quality in that video.

Note: if you keep getting a video without audio, refer to this answer on how to tackle it.

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
0

You can download it in lowest or highest quality by--

highest-

youtube.streams.get_highest_resolution.download()

lowest-

youtube.streams.get_lowest_resolution.download()
TANAY T
  • 1
  • 1
0

To list all available resolutions in a video, you can use the adaptive filter.

video = youtube("URL")
resolution = video.streams.filter(adaptive=true)

progressive=true allows you to view only progressive downloads. A progressive download is a legacy stream containing the audio and video in a single file, available for resolutions 720 and below.

Gitau Harrison
  • 3,179
  • 1
  • 19
  • 23
0

Because "progressive=True" in

for stream in youtube.streams.filter(progressive=True)

The highest quality you can get is 720p and below when "progressive=True", read this section on pytube docs it explains it all.

If u want the highest avaliable quality with the best audio u can do this by downloading the two files then merging them using ffmpeg.