private static void SearchFileName() { foreach (var movie in Movies) { string userConfirmation = "no"; string searchTerm = ""; OmdbResponseModel searchResult = new OmdbResponseModel(); while (userConfirmation != "yes" && searchTerm != "skip") { Console.WriteLine("Title: " + movie.OldFileName); Console.WriteLine("What should I search for? You may also skip this title by typing 'skip'"); SearchModel SM = new SearchModel(); searchTerm = Console.ReadLine(); if (searchTerm != "skip") { SM.Name = searchTerm; searchResult = omdbRequest.Search(SM); Console.WriteLine(searchResult.ToString()); Console.WriteLine("Are you happy with this result? yes, no, or skip?"); userConfirmation = Console.ReadLine(); } } if (userConfirmation == "yes") { movie.Title = searchResult.Title; movie.Year = searchResult.Year; movie.Rated = searchResult.Rated; movie.Released = searchResult.Released; movie.Runtime = searchResult.Runtime; movie.Genre = searchResult.Genre; movie.Director = searchResult.Director; movie.Writer = searchResult.Writer; movie.Actors = searchResult.Actors; movie.Plot = searchResult.Plot; movie.Language = searchResult.Language; movie.Country = searchResult.Country; movie.Awards = searchResult.Awards; movie.Poster = searchResult.Poster; movie.Metascore = searchResult.Metascore; movie.ImdbRating = searchResult.ImdbRating; movie.ImdbVotes = searchResult.ImdbVotes; movie.Type = searchResult.Type; var responseCode= FileManipulation.Rename(movie); if (responseCode) { Console.WriteLine("Rename was a success"); } else { Console.WriteLine("Rename failed"); } } } }
public static OmdbResponseModel Search(SearchModel SM) { string response = Request(createUrl(SM)); var Model = Converter(response); return Model; }
static string createUrl(SearchModel SM) { //Sample URL //http://www.omdbapi.com/?t=batman+begins&y=&plot=short&r=json string url = ""; string searchTerm = SM.Name; string[] searchList; string beginningUrl = "http://www.omdbapi.com/?"; string titleParameter = "t="; string yearParameter = "y="; string plotParameter = "plot=full"; string returnParameter = "r=json"; searchList = searchTerm.Split(' '); foreach (var word in searchList) { if (titleParameter == "t=") { titleParameter = (titleParameter + word); } else { titleParameter = (titleParameter + "+" + word); } } url = beginningUrl + titleParameter + "&" + yearParameter + "&" + plotParameter + "&" + returnParameter; return url; }