using System.Threading.Tasks;
static async Task Main(string[] args)
string uri = "https://www.youtube.com/watch?v=zU9y354XAgM";
var youTube = YouTube.Default;
var video = youTube.GetVideo(uri);
string fullName = video.FullName;
Console.WriteLine($"Downloading video: {fullName}");
using (Stream videoStream = video.Stream())
string filePath = @"C:\Users\admin\Desktop\e\" + fullName;
using (FileStream fileStream = File.Create(filePath))
byte[] buffer = new byte[8192];
while ((bytesRead = await videoStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
await fileStream.WriteAsync(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
DrawProgressBar(totalBytesRead, video.ContentLength);
Console.SetCursorPosition(0, Console.CursorTop);
Console.WriteLine($"Download complete: {fullName}");
static void DrawProgressBar(long completed, long? total)
int progressBarWidth = 50;
double progress = total.HasValue ? (double)completed / total.Value : 1.0;
int progressChars = (int)(progress * progressBarWidth);
string progressBar = "[" + new string('#', progressChars) + new string('.', progressBarWidth - progressChars) + "]";
Console.Write($"Downloading: {progressBar} {progress:P}");