private void ProcessMainInfo(MetadataResult <Series> seriesResult, RootObject seriesInfo, string preferredCountryCode, TmdbSettingsResult settings) { var series = seriesResult.Item; series.Name = seriesInfo.name; series.SetProviderId(MetadataProviders.Tmdb, seriesInfo.id.ToString(_usCulture)); //series.VoteCount = seriesInfo.vote_count; string voteAvg = seriesInfo.vote_average.ToString(CultureInfo.InvariantCulture); float rating; if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating)) { series.CommunityRating = rating; } series.Overview = seriesInfo.overview; if (seriesInfo.networks != null) { series.Studios = seriesInfo.networks.Select(i => i.name).ToArray(); } if (seriesInfo.genres != null) { series.Genres = seriesInfo.genres.Select(i => i.name).ToArray(); } //series.HomePageUrl = seriesInfo.homepage; series.RunTimeTicks = seriesInfo.episode_run_time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault(); if (string.Equals(seriesInfo.status, "Ended", StringComparison.OrdinalIgnoreCase)) { series.Status = SeriesStatus.Ended; series.EndDate = seriesInfo.last_air_date; } else { series.Status = SeriesStatus.Continuing; } series.PremiereDate = seriesInfo.first_air_date; var ids = seriesInfo.external_ids; if (ids != null) { if (!string.IsNullOrWhiteSpace(ids.imdb_id)) { series.SetProviderId(MetadataProviders.Imdb, ids.imdb_id); } if (ids.tvrage_id > 0) { series.SetProviderId(MetadataProviders.TvRage, ids.tvrage_id.ToString(_usCulture)); } if (ids.tvdb_id > 0) { series.SetProviderId(MetadataProviders.Tvdb, ids.tvdb_id.ToString(_usCulture)); } } var contentRatings = (seriesInfo.content_ratings ?? new ContentRatings()).results ?? new List <ContentRating>(); var ourRelease = contentRatings.FirstOrDefault(c => string.Equals(c.iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase)); var usRelease = contentRatings.FirstOrDefault(c => string.Equals(c.iso_3166_1, "US", StringComparison.OrdinalIgnoreCase)); var minimumRelease = contentRatings.FirstOrDefault(); if (ourRelease != null) { series.OfficialRating = ourRelease.rating; } else if (usRelease != null) { series.OfficialRating = usRelease.rating; } else if (minimumRelease != null) { series.OfficialRating = minimumRelease.rating; } if (seriesInfo.videos != null && seriesInfo.videos.results != null) { foreach (var video in seriesInfo.videos.results) { if (video.type.Equals("trailer", System.StringComparison.OrdinalIgnoreCase) || video.type.Equals("clip", System.StringComparison.OrdinalIgnoreCase)) { if (video.site.Equals("youtube", System.StringComparison.OrdinalIgnoreCase)) { var videoUrl = string.Format("http://www.youtube.com/watch?v={0}", video.key); series.AddTrailerUrl(videoUrl); } } } } seriesResult.ResetPeople(); var tmdbImageUrl = settings.images.GetImageUrl("original"); if (seriesInfo.credits != null && seriesInfo.credits.cast != null) { foreach (var actor in seriesInfo.credits.cast.OrderBy(a => a.order)) { var personInfo = new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order }; if (!string.IsNullOrWhiteSpace(actor.profile_path)) { personInfo.ImageUrl = tmdbImageUrl + actor.profile_path; } if (actor.id > 0) { personInfo.SetProviderId(MetadataProviders.Tmdb, actor.id.ToString(CultureInfo.InvariantCulture)); } seriesResult.AddPerson(personInfo); } } }
private void ProcessMainInfo(MetadataResult <Series> seriesResult, SeriesResult seriesInfo, string preferredCountryCode, TmdbSettingsResult settings) { var series = seriesResult.Item; series.Name = seriesInfo.Name; series.OriginalTitle = seriesInfo.Original_Name; series.SetProviderId(MetadataProvider.Tmdb, seriesInfo.Id.ToString(_usCulture)); string voteAvg = seriesInfo.Vote_Average.ToString(CultureInfo.InvariantCulture); if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out float rating)) { series.CommunityRating = rating; } series.Overview = seriesInfo.Overview; if (seriesInfo.Networks != null) { series.Studios = seriesInfo.Networks.Select(i => i.Name).ToArray(); } if (seriesInfo.Genres != null) { series.Genres = seriesInfo.Genres.Select(i => i.Name).ToArray(); } series.HomePageUrl = seriesInfo.Homepage; series.RunTimeTicks = seriesInfo.Episode_Run_Time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault(); if (string.Equals(seriesInfo.Status, "Ended", StringComparison.OrdinalIgnoreCase)) { series.Status = SeriesStatus.Ended; series.EndDate = seriesInfo.Last_Air_Date; } else { series.Status = SeriesStatus.Continuing; } series.PremiereDate = seriesInfo.First_Air_Date; var ids = seriesInfo.External_Ids; if (ids != null) { if (!string.IsNullOrWhiteSpace(ids.Imdb_Id)) { series.SetProviderId(MetadataProvider.Imdb, ids.Imdb_Id); } if (ids.Tvrage_Id > 0) { series.SetProviderId(MetadataProvider.TvRage, ids.Tvrage_Id.ToString(_usCulture)); } if (ids.Tvdb_Id > 0) { series.SetProviderId(MetadataProvider.Tvdb, ids.Tvdb_Id.ToString(_usCulture)); } } var contentRatings = (seriesInfo.Content_Ratings ?? new ContentRatings()).Results ?? new List <ContentRating>(); var ourRelease = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase)); var usRelease = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, "US", StringComparison.OrdinalIgnoreCase)); var minimumRelease = contentRatings.FirstOrDefault(); if (ourRelease != null) { series.OfficialRating = ourRelease.Rating; } else if (usRelease != null) { series.OfficialRating = usRelease.Rating; } else if (minimumRelease != null) { series.OfficialRating = minimumRelease.Rating; } if (seriesInfo.Videos != null && seriesInfo.Videos.Results != null) { foreach (var video in seriesInfo.Videos.Results) { if ((video.Type.Equals("trailer", StringComparison.OrdinalIgnoreCase) || video.Type.Equals("clip", StringComparison.OrdinalIgnoreCase)) && video.Site.Equals("youtube", StringComparison.OrdinalIgnoreCase)) { series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}"); } } } seriesResult.ResetPeople(); var tmdbImageUrl = settings.images.GetImageUrl("original"); if (seriesInfo.Credits != null) { if (seriesInfo.Credits.Cast != null) { foreach (var actor in seriesInfo.Credits.Cast.OrderBy(a => a.Order)) { var personInfo = new PersonInfo { Name = actor.Name.Trim(), Role = actor.Character, Type = PersonType.Actor, SortOrder = actor.Order }; if (!string.IsNullOrWhiteSpace(actor.Profile_Path)) { personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path; } if (actor.Id > 0) { personInfo.SetProviderId(MetadataProvider.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture)); } seriesResult.AddPerson(personInfo); } } if (seriesInfo.Credits.Crew != null) { var keepTypes = new[] { PersonType.Director, PersonType.Writer, PersonType.Producer }; foreach (var person in seriesInfo.Credits.Crew) { // Normalize this var type = TmdbUtils.MapCrewToPersonType(person); if (!keepTypes.Contains(type, StringComparer.OrdinalIgnoreCase) && !keepTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase)) { continue; } seriesResult.AddPerson(new PersonInfo { Name = person.Name.Trim(), Role = person.Job, Type = type }); } } } }