public DownloadSong() { Console.Clear(); Console.WriteLine("URL: "); YoutubeClient client = new YoutubeClient(); var video = client.Videos.GetAsync(Console.ReadLine()).Result; Console.Title = "BYTDownloader | Loading..."; var manifest = client.Videos.Streams.GetManifestAsync(video.Id).Result; Console.Title = "BYTDownloader"; var mediaStreamInfos = new[] { manifest.GetAudioOnly().WithHighestBitrate() }; string format = Format.mp3.ToString().ToLower(); var title = SharedMethods.CheckIfAvailableName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), video.Title, format); client.Videos.DownloadAsync(mediaStreamInfos, new ConversionRequestBuilder($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{title}.{format}").SetPreset(ConversionPreset.VerySlow).Build(), new Progress <double>((p) => SharedMethods.HandleProgress(p))).GetAwaiter().GetResult(); }
public async void DownloadFile() { int playlistLength = PlaylistVideos.Count(); int?answer = null; string Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Playlist"; if (Frmt == Format.mp4) { Console.Write("You can choose between these options:\n" + "1: Best quality\n" + "2: worst quality\n" + "3: Set manually for each video the quality\n" + "Your answer: "); answer = int.Parse(Console.ReadLine()); } Console.Title = "BYTDownloader"; for (int i = 0; i < playlistLength; i++) { try { var video = await client.Videos.GetAsync(PlaylistVideos.ElementAt(i).Url); var manifest = await client.Videos.Streams.GetManifestAsync(video.Id); if (Frmt == Format.mp4) { MediaStreamInfos = new IStreamInfo[] { manifest.GetAudioOnly().WithHighestBitrate(), manifest.GetVideoOnly().WithHighestVideoQuality() }; switch (answer.Value) { case 1: break; case 2: MediaStreamInfos[1] = manifest.GetVideoOnly().OrderByDescending(o => o.VideoQuality).ThenByDescending(o => o.Framerate).ThenByDescending(o => o.Bitrate).Last(); break; case 3: { var allqualities = manifest.GetVideoOnly().ToArray(); for (int j = 0; j < allqualities.Length; j++) { Console.WriteLine($"{j}: {allqualities[j].Resolution} - {allqualities[j].Framerate} - {allqualities[j].Bitrate} - {allqualities[j].Container}"); } Console.Write("Your answer: "); MediaStreamInfos[1] = manifest.GetVideoOnly().ToArray()[int.Parse(Console.ReadLine())]; break; } default: throw new Exception(); } } else if (Frmt == Format.mp3) //Sound { MediaStreamInfos = new IStreamInfo[] { manifest.GetAudioOnly().WithHighestBitrate() }; } string format = Frmt.ToString().ToLower(); var title = SharedMethods.CheckIfAvailableName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Playlist", PlaylistVideos[i].Title, format); client.Videos.DownloadAsync(MediaStreamInfos, new ConversionRequestBuilder($"{Path}\\{title}.{format}") .SetFormat(format).SetPreset(ConversionPreset.VerySlow).Build(), new Progress <double>((p) => SharedMethods.HandleProgress(p, true))).GetAwaiter().GetResult(); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{i + 1} / {playlistLength} has been skipped => ({PlaylistVideos[i].Title})"); Console.ResetColor(); continue; } Console.WriteLine($"{i + 1} / {playlistLength}"); } Console.ForegroundColor = ConsoleColor.Green; Thread.Sleep(1000); Console.WriteLine("Done"); }
private void HandleRequest(bool IsVideo) { List <IStreamInfo[]> StreamInfosList = new List <IStreamInfo[]>(); List <string> titles = new List <string>(); YoutubeClient client = new YoutubeClient(); string format = (IsVideo ? Format.mp4 : Format.mp3).ToString().ToLower(); if (IsVideo) { Console.Write("You can choose between these options:\n" + "1: Best quality\n" + "2: worst quality\n" + "3: Set manually for each video the quality\n" + "Your answer: "); int answer = int.Parse(Console.ReadLine()); for (int i = 0; i < tmp.Count; i++) { var video = client.Videos.GetAsync(tmp[i]).Result; var manifest = client.Videos.Streams.GetManifestAsync(video.Id).Result; var mediaStreamInfos = new IStreamInfo[] { manifest.GetAudioOnly().WithHighestBitrate(), manifest.GetVideoOnly().WithHighestVideoQuality() }; var title = SharedMethods.CheckIfAvailableName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), video.Title, format); switch (answer) { case 1: break; case 2: mediaStreamInfos[1] = manifest.GetVideoOnly().OrderByDescending(o => o.VideoQuality).ThenByDescending(o => o.Framerate).ThenByDescending(o => o.Bitrate).Last(); break; case 3: { var allqualities = manifest.GetVideoOnly().ToArray(); for (int j = 0; j < allqualities.Length; j++) { Console.WriteLine($"{j}: {allqualities[j].Resolution} - {allqualities[j].Framerate} - {allqualities[j].Bitrate} - {allqualities[j].Container}"); } Console.Write("Your answer: "); mediaStreamInfos[1] = manifest.GetVideoOnly().ToArray()[int.Parse(Console.ReadLine())]; break; } default: throw new Exception(); } StreamInfosList.Add(mediaStreamInfos); titles.Add(title); } } else { for (int i = 0; i < tmp.Count; i++) { var video = client.Videos.GetAsync(tmp[i]).Result; var manifest = client.Videos.Streams.GetManifestAsync(video.Id).Result; var mediaStreamInfos = new IStreamInfo[] { manifest.GetAudioOnly().WithHighestBitrate() }; var title = SharedMethods.CheckIfAvailableName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), video.Title, format); StreamInfosList.Add(mediaStreamInfos); titles.Add(title); } } for (int i = 0; i < StreamInfosList.Count; i++) { try { titles[i] = SharedMethods.CheckIfAvailableName(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), titles[i], format); client.Videos.DownloadAsync(StreamInfosList[i], new ConversionRequestBuilder($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{titles[i]}.{format}") .SetFormat(format).SetPreset(ConversionPreset.VerySlow).Build(), new Progress <double>((p) => SharedMethods.HandleProgress(p))).GetAwaiter().GetResult(); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{i + 1} / {StreamInfosList.Count} has been skipped => ({titles[i]})"); Console.ResetColor(); continue; } Console.WriteLine($"{i + 1} / {StreamInfosList.Count}"); } Console.ForegroundColor = ConsoleColor.Green; Thread.Sleep(1000); Console.WriteLine("Done"); }