Constructor

class Downloader(video, audio, metadata)

    Initializes the YouTube object with the provided video link.

Parameters:

    video MyTube.Stream Video stream object. (Optional)
    audio MyTube.Stream Audio stream object. (Optional)
    metadata dict Data for embedding in media file.

Properties

							CHUNK_SIZE
							int
							
						

    The size of the data that will be downloaded from the media stream at a time. (Default is 10MB)

							FFMPEG
							str
							
						

    Path to FFmpeg.exe. The default is just "ffmpeg", assuming FFmpeg is available in the system $PATH.

Methods

							async call(output_folder, filename, **kwargs) ->str
							
						

    Executes the download asynchronously. Can download video-only, audio-only, or both, and save them with the specified extensions and metadata.

Returns:

    str The path to the downloaded file.

Parameters:

    output_folder str Directory where the downloaded file will be saved.
    filename str Name for the downloaded file. Defaults to the title from metadata if available.
    video_ext str Preferred extension for the video file (mp4, webm).
    audio_ext str Preferred extension for the audio file. Defaults to mp3.
    add_audio_metadata bool If True, metadata (like title, author) is added to the audio file.
    on_progress func An async callback function to track download progress.
    ffmpeg_progress func An async callback function to track FFmpeg processing progress.
    on_success func A callback function to be called when the process completes successfully. (Returns the file path)
    on_abort func A callback function to be called if the process is aborted.

							abort()
							
						

    Stops the downloading process and file merging.

Example

Downloading video

import MyTube
import asyncio

def mb(bytes_value):
	return f"{round(bytes_value / (1024 * 1024))} MB"

async def progress(current, total):
	print(mb(current), "/", mb(total), end="\r")

async def ffmpeg_progress(current, total):
	print("Merging:", round(current * 100 / total), "%", end="\r")


async def main():
	yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
	video = yt.streams.best_video()
	audio = yt.streams.best_audio()
	print(video)
	print(audio)

	file = await yt.download(video=video, audio=audio)(
		"downloads", on_progress=progress, ffmpeg_progress=ffmpeg_progress
	)
	print(file)

asyncio.run(main())
Video(1920x1080.mp4 [25fps] av01.0.08M.08)
Audio(129.m4a [en] mp4a.40.2)

0 MB / 31 MB
[pause]
10 MB / 31 MB
[pause]
20 MB / 31 MB
[pause]
28 MB / 31 MB
[pause]
31 MB / 31 MB

Merging: 0 %
[pause]
Merging: 15 %
[pause]
Merging: 30 %
[pause]
Merging: 46 %
[pause]
Merging: 61 %
[pause]
Merging: 77 %
[pause]
Merging: 94 %
[pause]
Merging: 100 %

C:\Python\MyTube\downloads\Rick Astley - Never Gonna Give You Up (Official Music Video).mp4

Downloading music

import MyTube
import asyncio

def mb(bytes_value):
	return f"{round(bytes_value / (1024 * 1024))} MB"

async def progress(current, total):
	print(mb(current), "/", mb(total), end="\r")


async def main():
	yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
	audio = yt.streams.best_audio()
	print(audio)

	file = await yt.download(audio=audio)("downloads", "music", on_progress=progress)
	print(file)

asyncio.run(main())
Audio(129.m4a [en] mp4a.40.2)

0 MB / 3 MB
[pause]
3 MB / 3 MB

C:\Python\MyTube\downloads\music.mp3

Downloading muxed

import MyTube
import asyncio

def mb(bytes_value):
	return f"{round(bytes_value / (1024 * 1024))} MB"

async def progress(current, total):
	print(mb(current), "/", mb(total), end="\r")


async def main():
	yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
	stream = yt.streams.filter(only_muxed=True).first()
	print(stream)

	file = await yt.download(video=stream)("downloads", on_progress=progress)
	print(file)

asyncio.run(main())
Muxed(640x360.mp4 [25fps] [en] avc1.42001E+mp4a.40.2)

0 MB / 9 MB
[pause]
9 MB / 9 MB

C:\Python\MyTube\downloads\Rick Astley - Never Gonna Give You Up (Official Music Video) (1).mp4

Downloading stream

import MyTube
import asyncio

def mb(bytes_value):
	return f"{round(bytes_value / (1024 * 1024))} MB"

async def progress(current, total):
	print(mb(current), "/", mb(total), end="\r")


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

	stream = yt.streams.filter(
		only_video=True, no_muxed=True, max_res=720
	).order_by("res").first()
	
	print(stream)

	file = await stream.download("downloads", on_progress=progress)
	print(file)

asyncio.run(main())
Video(1280x720.mp4 [25fps] av01.0.05M.08)

0 MB / 15 MB
[pause]
10 MB / 15 MB
[pause]
15 MB / 15 MB

C:\Python\MyTube\downloads\Rick Astley - Never Gonna Give You Up (Official Music Video) (2).mp4

Aborting process

import MyTube
import asyncio
from threading import Timer

def mb(bytes_value):
	return f"{round(bytes_value / (1024 * 1024))} MB"

async def progress(current, total):
	print(mb(current), "/", mb(total), end="\r")


async def main():
	yt = MyTube.YouTube("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
	video = yt.streams.best_video()
	audio = yt.streams.best_audio()
	print(video)
	print(audio)

	downloader = yt.download(video=video, audio=audio)
	Timer(2, lambda: downloader.abort()).start()
	file = await downloader("downloads", on_progress=progress)

asyncio.run(main())