private string getTheMovieDbId(DBMovieInfo movie, bool fuzzyMatch) { // check for internally stored TMDb ID DBSourceMovieInfo idObj = movie.GetSourceMovieInfo(SourceInfo); if (idObj != null && idObj.Identifier != null) { return(idObj.Identifier); } // if available, lookup based on IMDb ID else if (movie.ImdbID != null && movie.ImdbID.Trim().Length == 9) { string imdbId = movie.ImdbID.Trim(); var movieInfo = TheMovieDbAPI.GetMovieInfo(imdbId); if (movieInfo != null) { return(movieInfo.Id.ToString()); } } // if asked for, do a fuzzy match based on title and year else if (fuzzyMatch) { // grab possible matches by main title + year List <DBMovieInfo> results = Search(movie.Title, movie.Year); if (results.Count == 0) { results = Search(movie.Title); } // grab possible matches by alt titles foreach (string currAltTitle in movie.AlternateTitles) { List <DBMovieInfo> tempResults = Search(movie.Title, movie.Year); if (tempResults.Count == 0) { tempResults = Search(movie.Title); } results.AddRange(tempResults); } // pick a possible match if one meets our requirements foreach (DBMovieInfo currMatch in results) { if (CloseEnough(currMatch, movie)) { return(currMatch.GetSourceMovieInfo(SourceInfo).Identifier); } } } return(null); }
private DBMovieInfo getMovieInformation(string movieId) { if (string.IsNullOrEmpty(movieId)) { return(null); } // request the movie details by imdb id or tmdb id var movieDetails = TheMovieDbAPI.GetMovieInfo(movieId, MovingPicturesCore.Settings.DataProviderLanguageCode); if (movieDetails == null) { return(null); } var movie = new DBMovieInfo(); // get the tmdb id movie.GetSourceMovieInfo(SourceInfo).Identifier = movieDetails.Id.ToString(); // get the localised title if available otherwise fallback to original title movie.Title = string.IsNullOrEmpty(movieDetails.Title) ? movieDetails.OriginalTitle : movieDetails.Title; // get alternative titles var altTitles = TheMovieDbAPI.GetAlternativeTitles(movieDetails.Id.ToString()); if (altTitles != null && altTitles.Titles != null) { movie.AlternateTitles.AddRange(altTitles.Titles.Select(a => a.Title)); } // get languages if (movieDetails.SpokenLanguages != null) { movie.Language = string.Join("|", movieDetails.SpokenLanguages.Select(l => l.Name).ToArray()); } // get tagline movie.Tagline = movieDetails.Tagline; // get imdb id movie.ImdbID = movieDetails.ImdbId; // get homepage movie.DetailsURL = movieDetails.HomePage; // get movie overview movie.Summary = movieDetails.Overview; // get movie score movie.Score = movieDetails.Score; // get movie vote count movie.Popularity = movieDetails.Votes; // get runtime (mins) movie.Runtime = movieDetails.Runtime == null ? 0 : (int)movieDetails.Runtime; // get movie cast var castInfo = TheMovieDbAPI.GetCastInfo(movieDetails.Id.ToString()); if (castInfo != null) { // add actors, sort by order field if (castInfo.Cast != null) { movie.Actors.AddRange(castInfo.Cast.OrderBy(a => a.Order).Select(a => a.Name)); } // add directors if (castInfo.Crew != null) { movie.Directors.AddRange(castInfo.Crew.Where(c => c.Department == "Directing").Select(c => c.Name).Distinct()); } // add writers if (castInfo.Crew != null) { movie.Writers.AddRange(castInfo.Crew.Where(c => c.Department == "Writing").Select(c => c.Name).Distinct()); } } // add genres if (movieDetails.Genres != null) { movie.Genres.AddRange(movieDetails.Genres.Select(g => g.Name).ToArray()); } // add collection - only one supported by TMDb if (movieDetails.BelongsToCollection != null) { // remove 'Collection' from name string collection = movieDetails.BelongsToCollection.Name.Replace("Collection", "").Trim(); movie.Collections.Add(collection); } // add production companies (studios) if (movieDetails.ProductionCompanies != null) { movie.Studios.AddRange(movieDetails.ProductionCompanies.Select(p => p.Name)); } // add release date and year DateTime date; if (DateTime.TryParse(movieDetails.ReleaseDate, out date)) { movie.Year = date.Year; movie.ReleaseDate = date; } // add certification (US MPAA rating) var movieCertifications = TheMovieDbAPI.GetReleaseInfo(movieDetails.Id.ToString()); if (movieCertifications != null && movieCertifications.Countries != null) { // this could also be a scraper setting to get certification and release date from preferred country var releaseInfo = movieCertifications.Countries.Find(c => c.CountryCode == "US"); if (releaseInfo != null) { movie.Certification = releaseInfo.Certification; // todo: uncomment this later if we have a setting for preferred country, it will override the release date that was previously set //if (DateTime.TryParse(releaseInfo.ReleaseDate, out date)) //{ // movie.ReleaseDate = date; //} } } // get plot keywords var plotKeywords = TheMovieDbAPI.GetPlotKeywords(movieDetails.Id.ToString()); if (plotKeywords != null) { movie.PlotKeywords.AddRange(plotKeywords.Keywords.Select(k => k.Name).ToArray()); } return(movie); }