Constructor

class StreamsManager(streams)

    Performs filtering and sorting operations to easily select a stream.

Parameters:

Properties

							streams
							list
							
						

Methods

							len()
							int
							
						

    Returns the number of streams managed by the instance.
    len(yt.streams)

							iter()
							
						

    Allows iteration over the list of streams.
    for stream in yt.streams:
    print(stream)

							filter(**kwargs) ->
							StreamsManager
							
						

    Filters the streams based on various options.

Parameters:

    only_video bool Filters to only include streams with video (either video-only or muxed).
    only_audio bool Filters to only include audio-only streams.
    only_muxed bool Filters to only include streams that contain both audio and video.
    no_muxed bool Filters out muxed streams (leaves only single video or audio streams).
    max_res int Maximum video resolution of the streams to be included.
    min_res int Minimum video resolution of the streams to be included.
    max_fps int Maximum video fps (frames per second) of the streams to be included.
    min_fps int Minimum video fps (frames per second) of the streams to be included.
    custom func A custom filter function that takes a stream as input and returns abool.

							order_by(attr, sub, reverse) ->
							StreamsManager
							
						

    Sorts the streams based on a specified attribute and optional secondary attribute.

Parameters:

    attr str The primary attribute to sort by.
    sub str A secondary attribute for sorting. (Optional)
    reverse bool Whether to sort in descending order. (Defaults to True)

							best_video() ->
							Stream
							
						

    Returns the best available video stream based on resolution and fps.

							best_audio() ->
							Stream
							
						

    Returns the best available audio stream based on bitrate.

							reverse() ->
							StreamsManager
							
						

    Reverses the order of the streams.

							first() ->
							Stream
							
						

    Returns the first stream in the list.

							last() ->
							Stream
							
						

    Returns the last stream in the list.

							get(itag) ->
							Stream
							
						

Parameters:

    itag str The unique identifier of the stream.

Example

Get all streams

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

print(f"Streams count: {len(yt.streams)}")
for stream in yt.streams:
	print(stream)
Streams count: 28

Audio(30.m4a [en] mp4a.40.5)
Audio(31.webm [en] opus)
Audio(48.m4a [en] mp4a.40.5)
Audio(46.webm [en] opus)
Audio(61.webm [en] opus)
Audio(129.m4a [en] mp4a.40.2)
Audio(129.webm [en] opus)
Video(256x144.mp4 [13fps] avc1.4d400b)
Video(256x144.webm [13fps] vp9)
Video(256x144.mp4 [25fps] av01.0.00M.08)
Video(256x144.mp4 [25fps] avc1.4D400C)
Video(256x144.webm [25fps] vp09.00.11.08)
Video(426x240.mp4 [25fps] av01.0.00M.08)
Video(426x240.mp4 [25fps] avc1.4D4015)
Video(426x240.webm [25fps] vp09.00.20.08)
Video(640x360.mp4 [25fps] av01.0.01M.08)
Video(640x360.mp4 [25fps] avc1.4D401E)
Muxed(640x360.mp4 [25fps] [en] avc1.42001E+mp4a.40.2)
Video(640x360.webm [25fps] vp09.00.21.08)
Video(854x480.mp4 [25fps] av01.0.04M.08)
Video(854x480.mp4 [25fps] avc1.4D401E)
Video(854x480.webm [25fps] vp09.00.30.08)
Video(1280x720.mp4 [25fps] av01.0.05M.08)
Video(1280x720.mp4 [25fps] avc1.4D401F)
Video(1280x720.webm [25fps] vp09.00.31.08)
Video(1920x1080.mp4 [25fps] av01.0.08M.08)
Video(1920x1080.mp4 [25fps] avc1.640028)
Video(1920x1080.webm [25fps] vp09.00.40.08)

Get video streams

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

streams = yt.streams.filter(
	only_video=True, no_muxed=True
).order_by("res", "fps")

for stream in streams:
	print(stream)
Video(1920x1080.mp4 [25fps] av01.0.08M.08)
Video(1920x1080.mp4 [25fps] avc1.640028)
Video(1920x1080.webm [25fps] vp09.00.40.08)
Video(1280x720.mp4 [25fps] av01.0.05M.08)
Video(1280x720.mp4 [25fps] avc1.4D401F)
Video(1280x720.webm [25fps] vp09.00.31.08)
Video(854x480.mp4 [25fps] av01.0.04M.08)
Video(854x480.mp4 [25fps] avc1.4D401E)
Video(854x480.webm [25fps] vp09.00.30.08)
Video(640x360.mp4 [25fps] av01.0.01M.08)
Video(640x360.mp4 [25fps] avc1.4D401E)
Video(640x360.webm [25fps] vp09.00.21.08)
Video(426x240.mp4 [25fps] av01.0.00M.08)
Video(426x240.mp4 [25fps] avc1.4D4015)
Video(426x240.webm [25fps] vp09.00.20.08)
Video(256x144.mp4 [25fps] av01.0.00M.08)
Video(256x144.mp4 [25fps] avc1.4D400C)
Video(256x144.webm [25fps] vp09.00.11.08)
Video(256x144.mp4 [13fps] avc1.4d400b)
Video(256x144.webm [13fps] vp9)

Get audio streams

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

streams = yt.streams.filter(only_audio=True).order_by("abr").streams

for stream in streams:
	print(stream)
Audio(129.m4a [en] mp4a.40.2)
Audio(129.webm [en] opus)
Audio(61.webm [en] opus)
Audio(48.m4a [en] mp4a.40.5)
Audio(46.webm [en] opus)
Audio(31.webm [en] opus)
Audio(30.m4a [en] mp4a.40.5)

Get best streams

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

print("Best video stream:")
video = yt.streams.best_video()
print(video)

print("Best audio stream:")
video = yt.streams.best_audio()
print(video)

print("Best muxed stream:")
muxed = yt.streams.filter(only_muxed=True).order_by("res").first()
print(muxed)
Best video stream:
Video(1920x1080.mp4 [25fps] av01.0.08M.08)

Best audio stream:
Audio(129.m4a [en] mp4a.40.2)

Best muxed stream:
Muxed(640x360.mp4 [25fps] [en] avc1.42001E+mp4a.40.2)

Limit video resolution

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

streams = yt.streams.filter(
	only_video=True, no_muxed=True, max_res=720, min_res=480
).order_by("res", "fps")

for stream in streams:
	print(stream)
Video(1280x720.mp4 [25fps] av01.0.05M.08)
Video(1280x720.mp4 [25fps] avc1.4D401F)
Video(1280x720.webm [25fps] vp09.00.31.08)
Video(854x480.mp4 [25fps] av01.0.04M.08)
Video(854x480.mp4 [25fps] avc1.4D401E)
Video(854x480.webm [25fps] vp09.00.30.08)

Get stream with specific language

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=Xj0Jtjg3lHQ")

de_stream = yt.streams.filter(only_audio=True,
	custom=lambda x: x.get("lang") == "de"
).order_by("abr").first()

print("Audio stream in German:")
print(de_stream)
Audio stream in German:
Audio(129.m4a [de] mp4a.40.2)

Get stream by itag

import MyTube
yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

for stream in yt.streams.filter(only_video=True, min_res=720):
	print(stream.itag, stream)

stream = yt.streams.get("248")
print("Target stream:")
print(stream)
398 Video(1280x720.mp4 [25fps] av01.0.05M.08)
136 Video(1280x720.mp4 [25fps] avc1.4D401F)
247 Video(1280x720.webm [25fps] vp09.00.31.08)
399 Video(1920x1080.mp4 [25fps] av01.0.08M.08)
137 Video(1920x1080.mp4 [25fps] avc1.640028)
248 Video(1920x1080.webm [25fps] vp09.00.40.08)

Target stream:
Video(1920x1080.webm [25fps] vp09.00.40.08)