private void LoadMovieStore(string movieName, int index) { Console.WriteLine(" Movie: {0}, index: {1}", movieName, index); var imDb = IoC.Get<IMDb>(); imDb.PrepareMovie(movieName); if (imDb.Id == null) { var foregroundColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Movie ({0}) could not be fetched!", movieName); Console.ForegroundColor = foregroundColor; return; } var item = new MovieStore { Awards = HttpUtility.HtmlDecode(imDb.Awards), Id = imDb.Id, ImdbUrl = imDb.ImdbURL, MpaaRating = imDb.MpaaRating, Nominations = imDb.Nominations, OriginalTitle = HttpUtility.HtmlDecode(imDb.OriginalTitle), Oscars = imDb.Oscars, Plot = HttpUtility.HtmlDecode(imDb.Plot), Poster = imDb.Poster, PosterFull = imDb.PosterFull, PosterLarge = imDb.PosterLarge, Rating = imDb.Rating, ReleaseDate = imDb.ReleaseDate, Runtime = imDb.Runtime, Storyline = HttpUtility.HtmlDecode(imDb.Storyline), Tagline = HttpUtility.HtmlDecode(imDb.Tagline), Title = HttpUtility.HtmlDecode(imDb.Title), Top250 = imDb.Top250, Votes = imDb.Votes, Year = imDb.Year }; if (imDb.Genres != null) { Debug.WriteLine(string.Format(" Genres: {0}", imDb.Genres.Count)); Console.WriteLine(" Genres: {0}", imDb.Genres.Count); foreach (var genre in imDb.Genres) { var htmlDecode = HttpUtility.HtmlDecode(genre.ToString()); item.Genres.Add(htmlDecode); } } if (imDb.Directors != null) { Debug.WriteLine(string.Format(" Directors: {0}", imDb.Directors.Count)); Console.WriteLine(" Directors: {0}", imDb.Directors.Count); foreach (var person in imDb.Directors) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Directors.ContainsKey(person.Key)) item.Directors.Add(person.Key, htmlDecode); } } if (imDb.Writers != null) { Debug.WriteLine(string.Format(" Writers: {0}", imDb.Writers.Count)); Console.WriteLine(" Writers: {0}", imDb.Writers.Count); foreach (var person in imDb.Writers) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Writers.ContainsKey(person.Key)) item.Writers.Add(person.Key, htmlDecode); } } if (imDb.Cast != null) { Debug.WriteLine(string.Format(" Cast: {0}", imDb.Cast.Count)); Console.WriteLine(" Cast: {0}", imDb.Cast.Count); foreach (var person in imDb.Cast) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Cast.ContainsKey(person.Key)) item.Cast.Add(person.Key, htmlDecode); } } if (imDb.Producers != null) { Debug.WriteLine(string.Format(" Producers: {0}", imDb.Producers.Count)); Console.WriteLine(" Producers: {0}", imDb.Producers.Count); foreach (var person in imDb.Producers) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Producers.ContainsKey(person.Key)) item.Producers.Add(person.Key, htmlDecode); } } if (imDb.Musicians != null) { Debug.WriteLine(string.Format(" Musicians: {0}", imDb.Musicians.Count)); Console.WriteLine(" Musicians: {0}", imDb.Musicians.Count); foreach (var person in imDb.Musicians) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Musicians.ContainsKey(person.Key)) item.Musicians.Add(person.Key, htmlDecode); } } if (imDb.Cinematographers != null) { Debug.WriteLine(string.Format(" Cinematographers: {0}", imDb.Cinematographers.Count)); Console.WriteLine(" Cinematographers: {0}", imDb.Cinematographers.Count); foreach (var person in imDb.Cinematographers) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Cinematographers.ContainsKey(person.Key)) item.Cinematographers.Add(person.Key, htmlDecode); } } if (imDb.Editors != null) { Debug.WriteLine(string.Format(" Editors: {0}", imDb.Editors.Count)); Console.WriteLine(" Editors: {0}", imDb.Editors.Count); foreach (var person in imDb.Editors) { var htmlDecode = HttpUtility.HtmlDecode(person.Value); if (!item.Editors.ContainsKey(person.Key)) item.Editors.Add(person.Key, htmlDecode); } } if (imDb.PlotKeywords != null) { Debug.WriteLine(string.Format(" PlotKeywords: {0}", imDb.PlotKeywords.Count)); Console.WriteLine(" PlotKeywords: {0}", imDb.PlotKeywords.Count); foreach (var plotKeyword in imDb.PlotKeywords) { var htmlDecode = HttpUtility.HtmlDecode(plotKeyword.ToString()); item.PlotKeywords.Add(htmlDecode); } } if (imDb.Languages != null) { Debug.WriteLine(string.Format(" Languages: {0}", imDb.Languages.Count)); Console.WriteLine(" Languages: {0}", imDb.Languages.Count); foreach (var language in imDb.Languages) { var htmlDecode = HttpUtility.HtmlDecode(language.ToString()); item.Languages.Add(htmlDecode); } } if (imDb.Countries != null) { Debug.WriteLine(string.Format(" Countries: {0}", imDb.Countries.Count)); Console.WriteLine(" Countries: {0}", imDb.Countries.Count); foreach (var country in imDb.Countries) { var htmlDecode = HttpUtility.HtmlDecode(country.ToString()); item.Countries.Add(htmlDecode); } } if (imDb.ReleaseDates != null) { Debug.WriteLine(string.Format(" ReleaseDates: {0}", imDb.ReleaseDates.Count)); Console.WriteLine(" ReleaseDates: {0}", imDb.ReleaseDates.Count); foreach (var releaseDate in imDb.ReleaseDates) { var htmlDecode = HttpUtility.HtmlDecode(releaseDate.ToString()); item.ReleaseDates.Add(htmlDecode); } } if (imDb.MediaImages != null) { Debug.WriteLine(string.Format(" MediaImages: {0}", imDb.MediaImages.Count)); Console.WriteLine(" MediaImages: {0}", imDb.MediaImages.Count); foreach (var mediaImage in imDb.MediaImages) { var htmlDecode = HttpUtility.HtmlDecode(mediaImage.ToString()); item.MediaImages.Add(htmlDecode); } } if (imDb.RecommendedTitles != null) { Debug.WriteLine(string.Format(" RecommendedTitles: {0}", imDb.RecommendedTitles.Count)); Console.WriteLine(" RecommendedTitles: {0}", imDb.RecommendedTitles.Count); foreach (var recommendedTitle in imDb.RecommendedTitles) { var htmlDecode = HttpUtility.HtmlDecode(recommendedTitle.ToString()); item.RecommendedTitles.Add(htmlDecode); } } _movieStore.Enqueue(item); SaveFile(item); Debug.WriteLine(string.Format("Item: {0}", item.Title)); Debug.WriteLine(string.Format(" Cast: {0}", item.Cast.Count)); Debug.WriteLine(string.Format(" Director: {0}", item.Directors.Count)); Debug.WriteLine(string.Format(" Genres: {0}", item.Genres.Count)); Console.WriteLine("--------------------"); }
private static void SaveFile(MovieStore item) { var itemJson = JsonConvert.SerializeObject(item, Formatting.None); var fileName = GenerateFileName(item.Title); using (var streamWriter = new StreamWriter(fileName)) { streamWriter.WriteLine(itemJson); streamWriter.Flush(); streamWriter.Close(); } }