JuanBindez / pytubefix

Python3 library for downloading YouTube Videos.
http://pytubefix.rtfd.io/
MIT License
674 stars 95 forks source link

Added optional parameter to obtain streams #136

Closed felipeucelli closed 3 months ago

felipeucelli commented 3 months ago

Added optional parameter to obtain streams #128

YouTube provides streams in two different formats, progressive streams that provide video and audio in a single file, and adaptive streams that provide video and audio in separate files.

Currently YouTube clients only provide progressive streams in 360p resolution.

This PR adds an optional parameter to get_highest_resolution() and get_lowest_resolution(), which allows you to get adaptive stream.

Example:

If I want the highest quality adaptive video, I just use:

yt_url = 'https://www.youtube.com/watch?v=60ItHLz5WEA'
yt = YouTube(yt_url)

print(yt.streams.get_highest_resolution(progressive=False))
<Stream: itag="399" mime_type="video/mp4" res="1080p" fps="25fps" vcodec="av01.0.08M.08" progressive="False" type="video">

Observe that if the progressive value is not passed, it will return the progressive stream:

yt_url = 'https://www.youtube.com/watch?v=60ItHLz5WEA'
yt = YouTube(yt_url)

print(yt.streams.get_highest_resolution())
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="25fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">
cedraz commented 3 months ago

How can I use pytubefix with this changes?