public static async Task <YoutubeVideo> GetVideoInformation(string videoId) { YoutubeVideo video = await Request.GetYoutubeVideoInfo <YoutubeVideo>(videoId); return(video); }
public override async Task OnCommandRecieved(Command cmd) { string commandName = cmd.LocalCommand; string userInput = cmd.UserInput; if (string.IsNullOrEmpty(ApiKey)) { if (!cmd.IsLocalCommand) { cmd.Respond("Invalid API Key."); } return; } if (commandName == "Play ID") { string id = RegisteredCommands[commandName].Match(userInput).Groups["id"].Value.ToString(); if (Current != null) { if (Current.IsLoaded) { Current.Close(); } } Application.Current.Dispatcher.Invoke(() => { Current = new YoutubeVideo(id); Current.Show(); }); } if (commandName == "Search") { Match m = RegisteredCommands[commandName].Match(userInput); string name = m.Groups["name"].Value.ToString(); if (!string.IsNullOrWhiteSpace(name)) { if (cmd.IsLocalCommand) { Application.Current.Dispatcher.Invoke(() => { new YoutubeSearch(name).Show(); }); } else { YouTubeService ys = new YouTubeService(new BaseClientService.Initializer() { ApiKey = YoutubeHook.ApiKey, ApplicationName = "Butler-YoutubeViewer" }); SearchResource.ListRequest req = new SearchResource.ListRequest(ys, "snippet") { Q = name, MaxResults = 30 }; LastSearchResponse = req.Execute(); string output = "Search Results:-\n"; for (int i = 0; i < LastSearchResponse.Items.Count; i++) { output += $"{i+1}.] {LastSearchResponse.Items[i].Snippet.Title}\n"; } cmd.Respond(output); } } } if (commandName == "Lucky Search") { Match m = RegisteredCommands[commandName].Match(userInput); YouTubeService ys = new YouTubeService(new BaseClientService.Initializer() { ApiKey = YoutubeHook.ApiKey, ApplicationName = "Butler-YoutubeViewer" }); SearchResource.ListRequest req = new SearchResource.ListRequest(ys, "snippet") { Q = m.Groups["name"].Value.ToString(), MaxResults = 1 }; SearchListResponse resp = req.Execute(); if (Current != null) { if (Current.IsLoaded) { Current.Close(); } } Application.Current.Dispatcher.Invoke(() => { Current = new YoutubeVideo(resp.Items[0].Id.VideoId); Current.Show(); }); } if (commandName == "Choose Option") { string choiceString = RegisteredCommands[cmd.LocalCommand].Match(cmd.UserInput).Groups["choice"].Value; int choiceInt; if (LastSearchResponse == null) { cmd.Respond("You didn't search for anything."); return; } if (!int.TryParse(choiceString, out choiceInt)) { cmd.Respond("That is not a number."); return; } choiceInt -= 1; if (choiceInt < 0 || choiceInt > LastSearchResponse.Items.Count - 1) { cmd.Respond("Dude.. Enter a acceptable value."); return; } if (Current != null) { if (Current.IsLoaded) { Current.Close(); } } Application.Current.Dispatcher.Invoke(() => { Current = new YoutubeVideo(LastSearchResponse.Items[choiceInt].Id.VideoId); Current.Show(); }); // Should I clear the search options after an option has been selected? //LastSearchResponse = null; } if (commandName == "Close") { if (Current != null) { if (Current.IsLoaded) { Current.Close(); } } } if (commandName == "State") { string state = RegisteredCommands[commandName].Match(userInput).Groups["state"].Value.ToLower(); switch (state) { case "min": case "minimize": State = WindowState.Minimized; break; case "max": case "maximize": State = WindowState.Maximized; break; } if (Current != null) { if (Current.IsLoaded) { if (State == WindowState.Maximized) { Current.Maximize(); } else { Current.Minimize(); } } } } }