public async void DownloadVideo(string uri, string directory, string format) { if (format == "1") { var youtube = new YoutubeClient(); var vid = await youtube.Videos.GetAsync(uri); YourTube yourTube = new YourTube(); if (File.Exists(directory + "\\" + vid.Title + ".mp4")) { yourTube.YourHaveVideo(); } else { var streamManifest = await youtube.Videos.Streams.GetManifestAsync(vid.Id); var streamInfo = streamManifest.GetMuxed().WithHighestVideoQuality(); if (streamInfo != null) { await youtube.Videos.Streams.GetAsync(streamInfo); await youtube.Videos.Streams.DownloadAsync(streamInfo, vid.Title + ".mp4"); } string data = Directory.GetCurrentDirectory() + "\\"; File.Move(data + vid.Title + ".mp4", directory + "\\" + vid.Title + ".mp4"); int index = 1; progressBar1.Invoke((int)index); yourTube.DownloadEn(); } } else { var youtube = new YoutubeClient(); var vid = await youtube.Videos.GetAsync(uri); // Get stream manifest var streamManifest = await youtube.Videos.Streams.GetManifestAsync(uri); // Select streams (1080p60 / highest bitrate audio) var audioStreamInfo = streamManifest.GetAudioOnly().WithHighestBitrate(); var videoStreamInfo = streamManifest.GetVideoOnly().Where(s => s.Container == Container.Mp4).WithHighestVideoQuality(); var streamInfos = new IStreamInfo[] { audioStreamInfo, videoStreamInfo }; // Download and process them into one file string data = Directory.GetCurrentDirectory() + "\\"; await youtube.Videos.DownloadAsync(streamInfos, new ConversionRequestBuilder("a").Build()); } }
public async void DownloadVideo(string url, string directory) { int counter = 0; var youtube = new YoutubeClient(); var videoID = url.Split('='); var streamManifest = await youtube.Videos.Streams.GetManifestAsync(videoID[1]); var vid = await youtube.Videos.GetAsync(url); var streamInfo = streamManifest.GetMuxed().WithHighestVideoQuality(); //var audioStreamInfo = streamManifest.GetAudio().WithHighestBitrate(); //var videoStreamInfo = streamManifest.GetVideo().FirstOrDefault(s => s.VideoQualityLabel == "1080p"); //if(videoStreamInfo == null) //{ // videoStreamInfo = streamManifest.GetVideo().FirstOrDefault(s => s.VideoQualityLabel == "720p"); //} //if (videoStreamInfo == null) //{ // videoStreamInfo = streamManifest.GetVideo().FirstOrDefault(s => s.VideoQualityLabel == "480p"); //} //if (videoStreamInfo == null) //{ // videoStreamInfo = streamManifest.GetVideo().FirstOrDefault(s => s.VideoQualityLabel == "360p"); //} //var streamInfo = new IStreamInfo[] { audioStreamInfo, videoStreamInfo }; if (streamInfo != null) { //var stream = await youtube.Videos.Streams.GetAsync(streamInfo); //File.Create("asd.mp4"); //await youtube.Videos.DownloadAsync(streamInfo, new ConversionRequestBuilder(directory).Build());//.SetFFmpegPath($"{directory}\\"). await youtube.Videos.Streams.DownloadAsync(streamInfo, $"{directory}\\{vid.Title}.mp4"); } //{vid.Title}.mp4 counter++; progressBarVideo.Invoke(counter); }