// This search returns one result, useful as a fallback when OMDB gives us a "too many results" error public static OmdbResult SearchOmdbForTitle(string searchTerms) { string response = ""; string url = $"http://www.omdbapi.com/?apikey={_omdbKey}&t={HttpUtility.UrlEncode(searchTerms)}"; using (WebClient wc = new WebClient()) { response = wc.DownloadString(url); } var result = OmdbResult.FromJson(response); return(result); }
private static void MainSearch() { List <Movie> searchedMovieList = new List <Movie>(); Console.Clear(); // Gets something to search for Console.WriteLine(_banner + "Type the name of the movie or show you want to search for:"); var input = Console.ReadLine().Trim(); while (string.IsNullOrWhiteSpace(input)) { Console.WriteLine("Please type something."); input = Console.ReadLine().Trim(); } var movieChoice = input; // Perform serch on OMDB Search[] omdbSearchResults = WebInteraction.SearchOmdbByString(movieChoice); // Put results into a list of movies with titles, directors, ratings, etc if (omdbSearchResults == null) { // Getting null is usually a "too many results" error, so we'll take what we get here OmdbResult newOmdbResults = WebInteraction.SearchOmdbForTitle(movieChoice); Movie movie = new Movie { Title = newOmdbResults.Title, ImdbId = newOmdbResults.ImdbId, Year = newOmdbResults.Year, Poster = newOmdbResults.Poster, Actors = newOmdbResults.Actors, Director = newOmdbResults.Director, ImdbRating = newOmdbResults.ImdbRating, Metascore = newOmdbResults.Metascore, Plot = newOmdbResults.Plot, Rated = newOmdbResults.Rated, Ratings = newOmdbResults.Ratings, }; searchedMovieList.Add(movie); } else { searchedMovieList = MovieInteraction.CreateListOfOmdbResults(omdbSearchResults); } Console.Clear(); Console.WriteLine($"You searched for {movieChoice}.\r\n\r\n"); ShowAndPickOmdbSearch(searchedMovieList); }
public static string ToJson(this OmdbResult self) => JsonConvert.SerializeObject(self, NowPlaying.Converter.Settings);