public void TestIsVideoDownload() { YoutubeDL ydlClient = new YoutubeDL(); var info = ydlClient.GetDownloadInfo(@"https://www.youtube.com/watch?v=dQw4w9WgXcQ"); Assert.NotNull(info as VideoDownloadInfo); }
public void TestIsPlaylistDownload() { YoutubeDL ydlClient = new YoutubeDL(); var info = ydlClient.GetDownloadInfo(@"https://www.youtube.com/playlist?list=PLrEnWoR732-BHrPp_Pm8_VleD68f9s14-"); Assert.NotNull(info as PlaylistDownloadInfo); }
public async Task PlayLocal(params string[] search) { int querypages = 1; var items = new VideoSearch(); var message = await Context.Channel.SendMessageAsync("Searching..."); var urls = items.SearchQuery(string.Join(" ", search), querypages); var duration = urls.First().Duration; var thumbnail = urls.First().Thumbnail; await message.ModifyAsync(msg => msg.Content = "Downloading " + urls.First().Title + "..."); var urlToDownload = urls.First().Url; var newFilename = Guid.NewGuid().ToString(); var mp3OutputFolder = Environment.CurrentDirectory + "/songs/"; var downloader = new YoutubeDL(); downloader.VideoUrl = urlToDownload; downloader.YoutubeDlPath = @"C:\Users\thoma\source\repos\CoolDiscordBot\CoolDiscordBot\bin\Debug\youtube-dl.exe"; downloader.Options.FilesystemOptions.Output = Environment.CurrentDirectory + "/songs/" + newFilename; downloader.PrepareDownload(); downloader.Download(); var info = downloader.GetDownloadInfo(); while (downloader.ProcessRunning == true) { await Task.Delay(50); } EmbedBuilder builder = new EmbedBuilder(); builder.Title = Context.User.Username + "#" + Context.User.Discriminator; builder.AddField("Name", info.Title); builder.ThumbnailUrl = thumbnail; builder.AddField("Duration", duration); builder.AddField("Url", urlToDownload); await ReplyAsync("t", false, builder.Build()); audioModule = new audiomodule(); var voiceChannel = ((IVoiceState)Context.User).VoiceChannel; if (voiceChannel is null) { await ReplyAsync($"{Context.User.Mention} you are not in a voice channel!"); return; } var audioClient = await voiceChannel.ConnectAsync().ConfigureAwait(false); Console.WriteLine(newFilename); string path = "\"" + Environment.CurrentDirectory + "/songs/" + newFilename + ".mkv" + "\""; await audioModule.PlayLocalMusic(path, audioClient); }
public void TestIsMultiDownload() { YoutubeDL ydlClient = new YoutubeDL(); ydlClient.VideoUrl = @"https://www.youtube.com/watch?v=dQw4w9WgXcQ https://www.youtube.com/playlist?list=PLrEnWoR732-BHrPp_Pm8_VleD68f9s14-"; var info = ydlClient.GetDownloadInfo(@"https://www.youtube.com/watch?v=dQw4w9WgXcQ https://www.youtube.com/playlist?list=PLrEnWoR732-BHrPp_Pm8_VleD68f9s14-"); Assert.NotNull(info as MultiDownloadInfo); }
public void TestIsVideoDownload() { YoutubeDL ydlClient = new YoutubeDL(); ydlClient.GetDownloadInfo(@"https://www.youtube.com/watch?v=dQw4w9WgXcQ"); VideoDownloadInfo info = ydlClient.Info as VideoDownloadInfo; Assert.NotEqual(info, null); }
private async void bGo_Click(object sender, RoutedEventArgs e) { textStatus.Text = "Preparing"; gridMain.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render); var downloader = new YoutubeDL(); string fileName = ""; downloader.VideoUrl = tbLink.Text; downloader.Options.FilesystemOptions.NoMtime = true; //downloader.Options.VideoFormatOptions.Format = NYoutubeDL.Helpers.Enums.VideoFormat.best; downloader.Options.VerbositySimulationOptions.CallHome = false; downloader.Options.GeneralOptions.Update = true; //downloader.Options.VideoFormatOptions.FormatAdvanced = string videoTitleNoFilter = downloader.GetDownloadInfo().Title; string videoTitle = Regex.Replace(videoTitleNoFilter, @"[^a-z,0-9, ,-]", "", RegexOptions.IgnoreCase); Random random = new Random(); int randomInt = random.Next(1, 1000); downloader.Options.FilesystemOptions.Output = filePath + $"\\video{randomInt}"; if (cboxCut.IsChecked == false && cboxConvert.IsChecked == false) { downloader.Options.FilesystemOptions.Output = filePath + $"\\{videoTitle}"; } downloader.YoutubeDlPath = runningPath + "\\youtube-dl.exe"; if (rbBest.IsChecked == true) { downloader.Options.VideoFormatOptions.FormatAdvanced = "best"; } else { downloader.Options.VideoFormatOptions.FormatAdvanced = "worst"; } if (cboxResolution.Text != "Auto") { downloader.Options.VideoFormatOptions.FormatAdvanced += $"[height <=? {Int32.Parse(cboxResolution.Text.TrimEnd('p'))}]"; } textStatus.Text = "Downloading"; downloader.DownloadAsync(); while (downloader.IsDownloading) { pbProgress.Value = downloader.Info.VideoProgress; textETA.Text = "ETA: " + downloader.Info.Eta; textSpeed.Text = "Speed: " + downloader.Info.DownloadRate; gridMain.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render); } pbProgress.Value = 0; textETA.Text = "ETA: ?"; textSpeed.Text = "Speed: ?"; gridMain.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render); foreach (string file in Directory.GetFiles(filePath)) { if (Path.GetFileName(file).StartsWith($"video{randomInt}")) { fileName = file; } } if (cboxCut.IsChecked == true || cboxConvert.IsChecked == true) { pbProgress.IsIndeterminate = true; textStatus.Text = "Getting FFmpeg"; gridMain.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render); if (!File.Exists(runningPath + "\\ffmpeg.exe")) { await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Full, runningPath); } textStatus.Text = "Processing"; gridMain.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.Render); var conversions = FFmpeg.Conversions.New(); if (cboxCut.IsChecked == true) { conversions.AddParameter($"-ss {TimeSpan.FromSeconds(Int32.Parse(tbFrom.Text))}"); } conversions.AddParameter($"-i \"{fileName}\""); if (cboxConvert.IsChecked == true) { conversions.SetOutput($"{filePath}\\{videoTitle}{cbConvertType.Text}"); } else { conversions.SetOutput($"{filePath}\\{videoTitle}{Path.GetExtension(fileName)}"); } if (cboxCut.IsChecked == true) { conversions.AddParameter($"-to {TimeSpan.FromSeconds(Int32.Parse(tbTo.Text) - Int32.Parse(tbFrom.Text))}"); } /* * if (cboxConvert.IsChecked == true && cboxCut.IsChecked == false) * await conversions.AddParameter($"-i \"{fileName}\" \"{filePath}\\{videoTitle}{cbConvertType.Text}\"").Start(); * if (cboxConvert.IsChecked == true && cboxCut.IsChecked == true) * await conversions.AddParameter($"-ss {TimeSpan.FromSeconds(Int32.Parse(tbFrom.Text))} -i \"{fileName}\" -to {TimeSpan.FromSeconds(Int32.Parse(tbTo.Text) - Int32.Parse(tbFrom.Text))} -c copy \"{filePath + $"\\{videoTitle}{cbConvertType.Text}"}\"").Start(); * if (cboxConvert.IsChecked == false && cboxCut.IsChecked == true) * await conversions.AddParameter($"-ss {TimeSpan.FromSeconds(Int32.Parse(tbFrom.Text))} -i \"{fileName}\" -to {TimeSpan.FromSeconds(Int32.Parse(tbTo.Text) - Int32.Parse(tbFrom.Text))} -c copy \"{filePath + $"\\{videoTitle}{Path.GetExtension(fileName)}"}\"").Start();*/ await conversions.Start(); File.Delete(fileName); pbProgress.IsIndeterminate = false; } textStatus.Text = "Idle"; }