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)