// Searches for the film with a name and year, returns info about the film. private FilmDetails searchForFilm(string name, string year, string str) { var json = ""; try{ using (var wc = new WebClient()){ // var name = "12 feet deep"; json = wc.DownloadString("https://api.themoviedb.org/3/search/movie?api_key=01080d24374dfd9c40970be178ae7948&language=en-US&query=" + name + "&page=1&year=" + year); } }catch (Exception) { Console.WriteLine("API FAILED"); return(null); } FilmInfoRaw account = JsonConvert.DeserializeObject <FilmInfoRaw>(json); return(getHighestMatched(str, account)); }
// Returns the film most likelyt to be the correct one. private FilmDetails getHighestMatched(string str, FilmInfoRaw account) { int score = 99999999; int num = 0; int size = account.results.Count; for (int i = 0; i < size; i++) { int a = levenshtein(str, (string)account.results[i]["title"]); if (a < score) { score = a; num = i; } } if (score == 99999999) { return(null); } else { Console.WriteLine("FOUND: " + account.results[num]["title"] + " SCORE: " + score); FilmDetails details = new FilmDetails(); details.title = account.results[num]["title"]; details.id = account.results[num]["id"]; details.overview = account.results[num]["overview"]; details.date = account.results[num]["release_date"]; details.poster = account.results[num]["poster_path"]; details.backdrop = account.results[num]["backdrop_path"]; details.rating = account.results[num]["vote_average"]; details.date = getYear(details.date); return(details); } }