private static DbMovieInfo GetMovieInformation(Tmdb api, TmdbMovie movieNode, string language) { LogMyFilms.Debug("GetMovieInformation() - language = '" + (language ?? "") + "'"); if (movieNode == null) return null; DbMovieInfo movie = new DbMovieInfo(); try { TmdbMovie m = api.GetMovieInfo(movieNode.id); movie.Identifier = m.id.ToString(); movie.ImdbId = m.imdb_id; movie.Name = m.original_title; movie.TranslatedTitle = m.title; movie.AlternativeTitle = m.original_title; DateTime date; if (DateTime.TryParse(m.release_date, out date)) movie.Year = date.Year; movie.DetailsUrl = m.homepage; movie.Summary = m.overview; movie.Score = (float)Math.Round(m.vote_average, 1); // movie.Certification = ""; foreach (SpokenLanguage spokenLanguage in m.spoken_languages) { movie.Languages.Add(spokenLanguage.name); } movie.Runtime = m.runtime; TmdbMovieCast p = api.GetMovieCast(movieNode.id); foreach (Cast cast in p.cast) { string name = cast.name; string character = cast.character; DbPersonInfo personToAdd = new DbPersonInfo { Id = cast.id.ToString(), Name = cast.name, DetailsUrl = cast.profile_path }; movie.Persons.Add(personToAdd); if (character.Length > 0) name = name + " (" + character + ")"; movie.Actors.Add(name); } foreach (Crew crew in p.crew) { DbPersonInfo personToAdd = new DbPersonInfo { Id = crew.id.ToString(), Name = crew.name, DetailsUrl = crew.profile_path }; movie.Persons.Add(personToAdd); switch (crew.department) { case "Production": movie.Producers.Add(crew.name); break; case "Directing": movie.Directors.Add(crew.name); break; case "Writing": movie.Writers.Add(crew.name); break; case "Sound": case "Camera": break; } } foreach (Cast cast in p.cast) { string name = cast.name; string character = cast.character; string thumb = cast.profile_path; string job = cast.character; string id = cast.id.ToString(); string url = cast.profile_path; var personToAdd = new DbPersonInfo { Id = id, Name = name, DetailsUrl = url, Job = job }; movie.Persons.Add(personToAdd); switch (job) { case "Producer": movie.Producers.Add(name); break; case "Director": movie.Directors.Add(name); break; case "Actor": if (character.Length > 0) name = name + " (" + character + ")"; movie.Actors.Add(name); break; case "Screenplay": movie.Writers.Add(name); break; } } foreach (ProductionCountry country in m.production_countries) { movie.Country.Add(country.name); } foreach (MovieGenre genre in m.genres) { movie.Country.Add(genre.name); } TmdbConfiguration tmdbConf = api.GetConfiguration(); // load posters TmdbMovieImages movieImages = api.GetMovieImages(movieNode.id, language); LogMyFilms.Debug("GetMovieInformation() - language = '" + (language ?? "") + "', Posters: '" + movieImages.posters.Count + "', Backdrops: '" + movieImages.backdrops.Count + "'"); foreach (Poster poster in movieImages.posters) { movie.Posters.Add(tmdbConf.images.base_url + "w500" + poster.file_path); } foreach (Backdrop backdrop in movieImages.backdrops) { movie.Backdrops.Add(tmdbConf.images.base_url + "original" + backdrop.file_path); } // english posters and backdrops movieImages = api.GetMovieImages(movieNode.id, "en"); // fallback to en language images LogMyFilms.Debug("GetMovieInformation() - language = 'en', Posters: '" + movieImages.posters.Count + "', Backdrops: '" + movieImages.backdrops.Count + "'"); if (movie.Posters.Count < 5) { foreach (Poster poster in movieImages.posters) { movie.Posters.Add(tmdbConf.images.base_url + "w500" + poster.file_path); } } foreach (Backdrop backdrop in movieImages.backdrops) { movie.Backdrops.Add(tmdbConf.images.base_url + "original" + backdrop.file_path); } // non language posters and backdrops movieImages = api.GetMovieImages(movieNode.id, null); // fallback to non language images LogMyFilms.Debug("GetMovieInformation() - language = 'null', Posters: '" + movieImages.posters.Count + "', Backdrops: '" + movieImages.backdrops.Count + "'"); if (movie.Posters.Count < 11) { foreach (Poster poster in movieImages.posters) { movie.Posters.Add(tmdbConf.images.base_url + "w500" + poster.file_path); } } if (movie.Backdrops.Count < 11) // only load foreign backdrops, if not anough are availabole { foreach (Backdrop backdrop in movieImages.backdrops) { movie.Backdrops.Add(tmdbConf.images.base_url + "original" + backdrop.file_path); } } LogMyFilms.Debug("GetMovieInformation() - Totals added - Posters: '" + movie.Posters.Count + "', Backdrops: '" + movie.Backdrops.Count + "'"); } catch (Exception ex) { LogMyFilms.Debug(ex.StackTrace); } return movie; }
private static DbMovieInfo GetMovieInformation(XmlNode movieNode) { if (movieNode == null) return null; if (movieNode.ChildNodes.Count < 2 || movieNode.Name != "movie") return null; var producers = new List<string>(); var directors = new List<string>(); var writers = new List<string>(); var actors = new List<string>(); var backdrops = new List<string>(); var posters = new List<string>(); var persons = new List<DbPersonInfo>(); var movie = new DbMovieInfo(); foreach (XmlNode node in movieNode.ChildNodes) { string value = node.InnerText; switch (node.Name) { case "id": movie.Identifier = value; break; case "name": case "title": movie.Name = value; break; case "alternative_name": if (value.Trim() != "None found." && value.Trim().Length > 0) movie.AlternativeTitle = value; break; case "original_name": if (value.Trim() != "None found." && value.Trim().Length > 0) movie.TranslatedTitle = value; break; case "released": case "release": DateTime date; if (DateTime.TryParse(value, out date)) movie.Year = date.Year; break; case "imdb": case "imdb_id": movie.ImdbId = value; break; case "url": movie.DetailsUrl = value; break; case "overview": case "short_overview": movie.Summary = value; break; case "rating": case "score": float rating = 0; if (float.TryParse(value, out rating)) movie.Score = rating; break; case "certification": movie.Certification = value; break; case "languages_spoken": foreach (XmlNode language in node.SelectNodes("language_spoken/name")) { movie.Languages.Add(language.InnerText.Trim()); } break; case "runtime": int runtime = 0; if (int.TryParse(value, out runtime)) movie.Runtime = runtime; break; case "people": case "cast": foreach (XmlNode person in node.ChildNodes) { string name = person.Attributes["name"].Value; string character = person.Attributes["character"].Value; string thumb = person.Attributes["thumb"].Value; string job = person.Attributes["job"].Value; string id = person.Attributes["id"].Value; string url = person.Attributes["url"].Value; var personToAdd = new DbPersonInfo { Id = id, Name = name, DetailsUrl = url, Job = job }; persons.Add(personToAdd); switch (job) { case "Producer": producers.Add(name); break; case "Director": directors.Add(name); break; case "Actor": if (character.Length > 0) name = name + " (" + character + ")"; actors.Add(name); break; case "Screenplay": writers.Add(name); break; } } break; case "countries": foreach (XmlNode country in node.SelectNodes("country/name")) { movie.Country.Add(country.InnerText.Trim()); } break; case "categories": foreach (XmlNode category in node.SelectNodes("category/name")) { movie.Genres.Add(category.InnerText.Trim()); } break; case "poster": if (node.OuterXml.Contains("\"original\"")) posters.Add(value); break; case "backdrop": if (node.OuterXml.Contains("\"original\"")) backdrops.Add(value); break; case "images": if (node.OuterXml.Contains("\"original\"") && node.OuterXml.Contains("\"backdrop\"") && node.OuterXml.Contains("url=")) { backdrops.AddRange(from XmlNode image in node.SelectNodes("image") where image.OuterXml.Contains("\"original\"") && image.OuterXml.Contains("\"backdrop\"") && image.OuterXml.Contains("url=") let start = image.OuterXml.IndexOf("url=") + 5 select image.OuterXml.Substring(start) into zvalue select zvalue.Substring(0, zvalue.IndexOf("\""))); } if (node.OuterXml.Contains("\"original\"") && node.OuterXml.Contains("\"poster\"") && node.OuterXml.Contains("url=")) { posters.AddRange(from XmlNode image in node.SelectNodes("image") where image.OuterXml.Contains("\"original\"") && image.OuterXml.Contains("\"poster\"") && image.OuterXml.Contains("url=") let start = image.OuterXml.IndexOf("url=") + 5 select image.OuterXml.Substring(start) into zvalue select zvalue.Substring(0, zvalue.IndexOf("\""))); } break; } } movie.Producers = producers; movie.Directors = directors; movie.Writers = writers; movie.Actors = actors; movie.Backdrops = backdrops; movie.Posters = posters; movie.Persons = persons; return movie; }