private void AddGuestStars(BaseItem item, string val) { // Sometimes tvdb actors have leading spaces //Regex Info: //The first block are the posible delimitators (open-parentheses should be there cause if dont the next block will fail) //The second block Allow the delimitators to be part of the text if they're inside parentheses var persons = Regex.Matches(val, @"(?<delimitators>([^|,(])|(?<ignoreinParentheses>\([^)]*\)*))+") .Cast <Match>() .Select(m => m.Value) .Where(i => !string.IsNullOrWhiteSpace(i) && !string.IsNullOrEmpty(i)); foreach (var person in persons.Select(str => { var nameGroup = str.Split(new[] { '(' }, 2, StringSplitOptions.RemoveEmptyEntries); var name = nameGroup[0].Trim(); var roles = nameGroup.Count() > 1 ? nameGroup[1].Trim() : null; if (roles != null) { roles = roles.EndsWith(")") ? roles.Substring(0, roles.Length - 1) : roles; } return(new PersonInfo { Type = PersonType.GuestStar, Name = name, Role = roles }); })) { item.AddPerson(person); } }
private void AddPeople(BaseItem item, string val, string personType) { // Sometimes tvdb actors have leading spaces foreach (var person in val.Split(new[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries) .Where(i => !string.IsNullOrWhiteSpace(i)) .Select(str => new PersonInfo { Type = personType, Name = str.Trim() })) { item.AddPerson(person); } }
/// <summary> /// Processes the main info. /// </summary> /// <param name="movie">The movie.</param> /// <param name="movieData">The movie data.</param> protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData) { if (movie != null && movieData != null) { if (!movie.LockedFields.Contains(MetadataFields.Name)) { movie.Name = movieData.title ?? movieData.original_title ?? movie.Name; } if (!movie.LockedFields.Contains(MetadataFields.Overview)) { movie.Overview = WebUtility.HtmlDecode(movieData.overview); } movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null; movie.HomePageUrl = movieData.homepage; movie.Budget = movieData.budget; movie.Revenue = movieData.revenue; if (!string.IsNullOrEmpty(movieData.tagline)) { movie.Taglines.Clear(); movie.AddTagline(movieData.tagline); } movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id); if (movieData.belongs_to_collection != null) { movie.SetProviderId(MetadataProviders.TmdbCollection, movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture)); } float rating; string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture); //tmdb appears to have unified their numbers to always report "7.3" regardless of country // so I removed the culture-specific processing here because it was not working for other countries -ebr if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating)) movie.CommunityRating = rating; movie.VoteCount = movieData.vote_count; //release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match if (movieData.releases != null && movieData.releases.countries != null) { var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(ConfigurationManager.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country(); var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country(); var minimunRelease = movieData.releases.countries.OrderBy(c => c.release_date).FirstOrDefault() ?? new Country(); var ratingPrefix = ConfigurationManager.Configuration.MetadataCountryCode.Equals("us", StringComparison.OrdinalIgnoreCase) ? "" : ConfigurationManager.Configuration.MetadataCountryCode + "-"; movie.OfficialRating = !string.IsNullOrEmpty(ourRelease.certification) ? ratingPrefix + ourRelease.certification : !string.IsNullOrEmpty(usRelease.certification) ? usRelease.certification : !string.IsNullOrEmpty(minimunRelease.certification) ? minimunRelease.iso_3166_1 + "-" + minimunRelease.certification : null; if (ourRelease.release_date != default(DateTime)) { if (ourRelease.release_date.Year != 1) { movie.PremiereDate = ourRelease.release_date.ToUniversalTime(); movie.ProductionYear = ourRelease.release_date.Year; } } else if (usRelease.release_date != default(DateTime)) { if (usRelease.release_date.Year != 1) { movie.PremiereDate = usRelease.release_date.ToUniversalTime(); movie.ProductionYear = usRelease.release_date.Year; } } else if (minimunRelease.release_date != default(DateTime)) { if (minimunRelease.release_date.Year != 1) { movie.PremiereDate = minimunRelease.release_date.ToUniversalTime(); movie.ProductionYear = minimunRelease.release_date.Year; } } } else { if (movieData.release_date.Year != 1) { //no specific country release info at all movie.PremiereDate = movieData.release_date.ToUniversalTime(); movie.ProductionYear = movieData.release_date.Year; } } //if that didn't find a rating and we are a boxset, use the one from our first child if (movie.OfficialRating == null && movie is BoxSet) { var boxset = movie as BoxSet; Logger.Info("MovieDbProvider - Using rating of first child of boxset..."); var firstChild = boxset.Children.Concat(boxset.GetLinkedChildren()).FirstOrDefault(); boxset.OfficialRating = firstChild != null ? firstChild.OfficialRating : null; } if (movieData.runtime > 0) movie.OriginalRunTimeTicks = TimeSpan.FromMinutes(movieData.runtime).Ticks; //studios if (movieData.production_companies != null && !movie.LockedFields.Contains(MetadataFields.Studios)) { movie.Studios.Clear(); foreach (var studio in movieData.production_companies.Select(c => c.name)) { movie.AddStudio(studio); } } //genres if (movieData.genres != null && !movie.LockedFields.Contains(MetadataFields.Genres)) { movie.Genres.Clear(); foreach (var genre in movieData.genres.Select(g => g.name)) { movie.AddGenre(genre); } } if (!movie.LockedFields.Contains(MetadataFields.Cast)) { movie.People.Clear(); //Actors, Directors, Writers - all in People //actors come from cast if (movieData.casts != null && movieData.casts.cast != null) { foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor }); } //and the rest from crew if (movieData.casts != null && movieData.casts.crew != null) { foreach (var person in movieData.casts.crew) movie.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department }); } } if (movieData.keywords != null && movieData.keywords.keywords != null && !movie.LockedFields.Contains(MetadataFields.Tags)) { movie.Tags = movieData.keywords.keywords.Select(i => i.name).ToList(); } if (movieData.trailers != null && movieData.trailers.youtube != null && movieData.trailers.youtube.Count > 0) { movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl { Url = string.Format("http://www.youtube.com/watch?v={0}", i.source), IsDirectLink = false, Name = i.name, VideoSize = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) ? VideoSize.HighDefinition : VideoSize.StandardDefinition }).ToList(); } } }
/// <summary> /// Processes the main info. /// </summary> /// <param name="movie">The movie.</param> /// <param name="movieData">The movie data.</param> protected virtual void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData) { if (movie != null && movieData != null) { if (!movie.LockedFields.Contains(MetadataFields.Name)) { movie.Name = movieData.title ?? movieData.original_title ?? movieData.name ?? movie.Name; } if (!movie.LockedFields.Contains(MetadataFields.Overview)) { movie.Overview = WebUtility.HtmlDecode(movieData.overview); movie.Overview = movie.Overview != null?movie.Overview.Replace("\n\n", "\n") : null; } movie.HomePageUrl = movieData.homepage; movie.Budget = movieData.budget; movie.Revenue = movieData.revenue; if (!string.IsNullOrEmpty(movieData.tagline)) { movie.Taglines.Clear(); movie.AddTagline(movieData.tagline); } movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id); if (movieData.belongs_to_collection != null) { movie.SetProviderId(MetadataProviders.TmdbCollection, movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture)); } else { movie.SetProviderId(MetadataProviders.TmdbCollection, null); // clear out any old entry } float rating; string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture); //tmdb appears to have unified their numbers to always report "7.3" regardless of country // so I removed the culture-specific processing here because it was not working for other countries -ebr if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating)) { movie.CommunityRating = rating; } movie.VoteCount = movieData.vote_count; //release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match if (movieData.releases != null && movieData.releases.countries != null) { var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(ConfigurationManager.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country(); var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country(); var minimunRelease = movieData.releases.countries.OrderBy(c => c.release_date).FirstOrDefault() ?? new Country(); var ratingPrefix = ConfigurationManager.Configuration.MetadataCountryCode.Equals("us", StringComparison.OrdinalIgnoreCase) ? "" : ConfigurationManager.Configuration.MetadataCountryCode + "-"; movie.OfficialRating = !string.IsNullOrEmpty(ourRelease.certification) ? ratingPrefix + ourRelease.certification : !string.IsNullOrEmpty(usRelease.certification) ? usRelease.certification : !string.IsNullOrEmpty(minimunRelease.certification) ? minimunRelease.iso_3166_1 + "-" + minimunRelease.certification : null; if (ourRelease.release_date != default(DateTime)) { if (ourRelease.release_date.Year != 1) { movie.PremiereDate = ourRelease.release_date.ToUniversalTime(); movie.ProductionYear = ourRelease.release_date.Year; } } else if (usRelease.release_date != default(DateTime)) { if (usRelease.release_date.Year != 1) { movie.PremiereDate = usRelease.release_date.ToUniversalTime(); movie.ProductionYear = usRelease.release_date.Year; } } else if (minimunRelease.release_date != default(DateTime)) { if (minimunRelease.release_date.Year != 1) { movie.PremiereDate = minimunRelease.release_date.ToUniversalTime(); movie.ProductionYear = minimunRelease.release_date.Year; } } } else { if (movieData.release_date.Year != 1) { //no specific country release info at all movie.PremiereDate = movieData.release_date.ToUniversalTime(); movie.ProductionYear = movieData.release_date.Year; } } //if that didn't find a rating and we are a boxset, use the one from our first child if (movie.OfficialRating == null && movie is BoxSet) { var boxset = movie as BoxSet; Logger.Info("MovieDbProvider - Using rating of first child of boxset..."); var firstChild = boxset.Children.Concat(boxset.GetLinkedChildren()).FirstOrDefault(); boxset.OfficialRating = firstChild != null ? firstChild.OfficialRating : null; } if (movieData.runtime > 0) { movie.OriginalRunTimeTicks = TimeSpan.FromMinutes(movieData.runtime).Ticks; } //studios if (movieData.production_companies != null && !movie.LockedFields.Contains(MetadataFields.Studios)) { movie.Studios.Clear(); foreach (var studio in movieData.production_companies.Select(c => c.name)) { movie.AddStudio(studio); } } //genres if (movieData.genres != null && !movie.LockedFields.Contains(MetadataFields.Genres)) { movie.Genres.Clear(); foreach (var genre in movieData.genres.Select(g => g.name)) { movie.AddGenre(genre); } } if (!movie.LockedFields.Contains(MetadataFields.Cast)) { movie.People.Clear(); //Actors, Directors, Writers - all in People //actors come from cast if (movieData.casts != null && movieData.casts.cast != null) { foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) { movie.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor }); } } //and the rest from crew if (movieData.casts != null && movieData.casts.crew != null) { foreach (var person in movieData.casts.crew) { movie.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department }); } } } if (movieData.keywords != null && movieData.keywords.keywords != null && !movie.LockedFields.Contains(MetadataFields.Tags)) { movie.Tags = movieData.keywords.keywords.Select(i => i.name).ToList(); } if (movieData.trailers != null && movieData.trailers.youtube != null && movieData.trailers.youtube.Count > 0) { movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl { Url = string.Format("http://www.youtube.com/watch?v={0}", i.source), IsDirectLink = false, Name = i.name, VideoSize = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) ? VideoSize.HighDefinition : VideoSize.StandardDefinition }).ToList(); } } }
/// <summary> /// Processes the main info. /// </summary> /// <param name="movie">The movie.</param> /// <param name="movieData">The movie data.</param> private void ProcessMainInfo(BaseItem movie, CompleteMovieData movieData) { if (!movie.LockedFields.Contains(MetadataFields.Name)) { movie.Name = movieData.title ?? movieData.original_title ?? movieData.name ?? movie.Name; } if (!movie.LockedFields.Contains(MetadataFields.Overview)) { // Bug in Mono: WebUtility.HtmlDecode should return null if the string is null but in Mono it generate an System.ArgumentNullException. movie.Overview = movieData.overview != null ? WebUtility.HtmlDecode(movieData.overview) : null; movie.Overview = movie.Overview != null ? movie.Overview.Replace("\n\n", "\n") : null; } movie.HomePageUrl = movieData.homepage; var hasBudget = movie as IHasBudget; if (hasBudget != null) { hasBudget.Budget = movieData.budget; hasBudget.Revenue = movieData.revenue; } if (!string.IsNullOrEmpty(movieData.tagline)) { var hasTagline = movie as IHasTaglines; if (hasTagline != null) { hasTagline.Taglines.Clear(); hasTagline.AddTagline(movieData.tagline); } } movie.SetProviderId(MetadataProviders.Tmdb, movieData.id.ToString(_usCulture)); movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id); if (movieData.belongs_to_collection != null) { movie.SetProviderId(MetadataProviders.TmdbCollection, movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture)); var movieItem = movie as Movie; if (movieItem != null) { movieItem.TmdbCollectionName = movieData.belongs_to_collection.name; } } else { movie.SetProviderId(MetadataProviders.TmdbCollection, null); // clear out any old entry } float rating; string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture); // tmdb appears to have unified their numbers to always report "7.3" regardless of country // so I removed the culture-specific processing here because it was not working for other countries -ebr // Movies get this from imdb if (!(movie is Movie) && float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating)) { movie.CommunityRating = rating; } // Movies get this from imdb if (!(movie is Movie)) { movie.VoteCount = movieData.vote_count; } var preferredCountryCode = movie.GetPreferredMetadataCountryCode(); //release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match if (movieData.releases != null && movieData.releases.countries != null) { var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(preferredCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country(); var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country(); var minimunRelease = movieData.releases.countries.OrderBy(c => c.release_date).FirstOrDefault() ?? new Country(); if (!movie.LockedFields.Contains(MetadataFields.OfficialRating)) { var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-"; movie.OfficialRating = !string.IsNullOrEmpty(ourRelease.certification) ? ratingPrefix + ourRelease.certification : !string.IsNullOrEmpty(usRelease.certification) ? usRelease.certification : !string.IsNullOrEmpty(minimunRelease.certification) ? minimunRelease.iso_3166_1 + "-" + minimunRelease.certification : null; } } if (movieData.release_date.Year != 1) { //no specific country release info at all movie.PremiereDate = movieData.release_date.ToUniversalTime(); movie.ProductionYear = movieData.release_date.Year; } // If that didn't find a rating and we are a boxset, use the one from our first child if (movie.OfficialRating == null && movie is BoxSet && !movie.LockedFields.Contains(MetadataFields.OfficialRating)) { var boxset = movie as BoxSet; Logger.Info("MovieDbProvider - Using rating of first child of boxset..."); var firstChild = boxset.Children.Concat(boxset.GetLinkedChildren()).FirstOrDefault(); boxset.OfficialRating = firstChild != null ? firstChild.OfficialRating : null; } //studios if (movieData.production_companies != null && !movie.LockedFields.Contains(MetadataFields.Studios)) { movie.Studios.Clear(); foreach (var studio in movieData.production_companies.Select(c => c.name)) { movie.AddStudio(studio); } } // genres // Movies get this from imdb var genres = movieData.genres ?? new List<GenreItem>(); if (!movie.LockedFields.Contains(MetadataFields.Genres)) { // Only grab them if a boxset or there are no genres. // For movies and trailers we'll use imdb via omdb // But omdb data is for english users only so fetch if language is not english if (!(movie is Movie) || movie.Genres.Count == 0 || !string.Equals(movie.GetPreferredMetadataLanguage(), "en", StringComparison.OrdinalIgnoreCase)) { movie.Genres.Clear(); foreach (var genre in genres.Select(g => g.name)) { movie.AddGenre(genre); } } } if (!movie.LockedFields.Contains(MetadataFields.Cast)) { movie.People.Clear(); //Actors, Directors, Writers - all in People //actors come from cast if (movieData.casts != null && movieData.casts.cast != null) { foreach (var actor in movieData.casts.cast.OrderBy(a => a.order)) movie.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order }); } //and the rest from crew if (movieData.casts != null && movieData.casts.crew != null) { foreach (var person in movieData.casts.crew) movie.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department }); } } if (movieData.keywords != null && movieData.keywords.keywords != null && !movie.LockedFields.Contains(MetadataFields.Keywords)) { var hasTags = movie as IHasKeywords; if (hasTags != null) { hasTags.Keywords = movieData.keywords.keywords.Select(i => i.name).ToList(); } } if (movieData.trailers != null && movieData.trailers.youtube != null && movieData.trailers.youtube.Count > 0) { var hasTrailers = movie as IHasTrailers; if (hasTrailers != null) { hasTrailers.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl { Url = string.Format("http://www.youtube.com/watch?v={0}", i.source), IsDirectLink = false, Name = i.name, VideoSize = string.Equals("hd", i.size, StringComparison.OrdinalIgnoreCase) ? VideoSize.HighDefinition : VideoSize.StandardDefinition }).ToList(); } } }
private void AddGuestStars(BaseItem item, string val) { // Sometimes tvdb actors have leading spaces //Regex Info: //The first block are the posible delimitators (open-parentheses should be there cause if dont the next block will fail) //The second block Allow the delimitators to be part of the text if they're inside parentheses var persons = Regex.Matches(val, @"(?<delimitators>([^|,(])|(?<ignoreinParentheses>\([^)]*\)*))+") .Cast<Match>() .Select(m => m.Value) .Where(i => !string.IsNullOrWhiteSpace(i) && !string.IsNullOrEmpty(i)); foreach (var person in persons.Select(str => { var nameGroup = str.Split(new[] { '(' }, 2, StringSplitOptions.RemoveEmptyEntries); var name = nameGroup[0].Trim(); var roles = nameGroup.Count() > 1 ? nameGroup[1].Trim() : null; if (roles != null) roles = roles.EndsWith(")") ? roles.Substring(0, roles.Length - 1) : roles; return new PersonInfo { Type = PersonType.GuestStar, Name = name, Role = roles }; })) { item.AddPerson(person); } }
private void AddPeople(BaseItem item, string val, string personType) { // Sometimes tvdb actors have leading spaces foreach (var person in val.Split(new[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries) .Where(i => !string.IsNullOrWhiteSpace(i)) .Select(str => new PersonInfo { Type = personType, Name = str.Trim() })) { item.AddPerson(person); } }