public MovieCertificationCountry() { List <RegionInfo> regions = CertificationMapper.GetSupportedMovieCertificationCountries().Select(r => new RegionInfo(r)).ToList(); regions.Sort(CompareByName); _regions = regions; }
public override async Task <bool> UpdateFromOnlineMovieAsync(MovieInfo movie, string language, bool cacheOnly) { try { SimApiMovie movieDetail = null; if (!string.IsNullOrEmpty(movie.ImdbId)) { movieDetail = await _simApiHandler.GetMovieAsync(movie.ImdbId, cacheOnly).ConfigureAwait(false); } if (movieDetail == null) { return(false); } movie.ImdbId = movieDetail.ImdbID; movie.MovieName = new SimpleTitle(movieDetail.Title, true); movie.Summary = new SimpleTitle(movieDetail.Plot, true); CertificationMapping cert = null; if (CertificationMapper.TryFindMovieCertification(movieDetail.Rated, out cert)) { movie.Certification = cert.CertificationId; } movie.Runtime = movieDetail.Duration.HasValue ? movieDetail.Duration.Value : 0; movie.ReleaseDate = movieDetail.Year.HasValue ? (DateTime?)new DateTime(movieDetail.Year.Value, 1, 1) : null; if (movieDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.ImdbRating, 1)); } movie.Genres = movieDetail.Genres.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (movie.Actors.Count == 0) { movie.Actors = ConvertToPersons(movieDetail.Actors, PersonAspect.OCCUPATION_ACTOR, movieDetail.Title); } if (movie.Writers.Count == 0) { movie.Writers = ConvertToPersons(movieDetail.Writers, PersonAspect.OCCUPATION_WRITER, movieDetail.Title); } //if (movie.Directors.Count == 0) // movie.Directors = ConvertToPersons(movieDetail.Directors, PersonAspect.OCCUPATION_DIRECTOR, movieDetail.Title); return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("SimApiWrapper: Exception while processing movie {0}", ex, movie.ToString()); return(false); } }
public static void ConvertCertifications(IEnumerable <MediaItem> mediaItems) { if (mediaItems == null) { return; } //Convert certification system if needed if (!string.IsNullOrEmpty(DisplayMovieCertificationCountry) || !string.IsNullOrEmpty(DisplaySeriesCertificationCountry)) { foreach (MediaItem mediaItem in mediaItems.Where(mi => mi.Aspects.ContainsKey(MovieAspect.ASPECT_ID) || mi.Aspects.ContainsKey(SeriesAspect.ASPECT_ID))) { //Find all possible matches string certification = null; CertificationMapping bestMatch = null; if (mediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID) && !string.IsNullOrEmpty(DisplayMovieCertificationCountry)) { if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, MovieAspect.ATTR_CERTIFICATION, out certification)) { bestMatch = CertificationMapper.FindMatchingMovieCertification(DisplayMovieCertificationCountry, certification); } } if (mediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID) && !string.IsNullOrEmpty(DisplaySeriesCertificationCountry)) { if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, SeriesAspect.ATTR_CERTIFICATION, out certification)) { bestMatch = CertificationMapper.FindMatchingSeriesCertification(DisplaySeriesCertificationCountry, certification); } } //Assign new certification value if (bestMatch != null) { if (mediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, MovieAspect.ATTR_CERTIFICATION, bestMatch.CertificationId); } else if (mediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, SeriesAspect.ATTR_CERTIFICATION, bestMatch.CertificationId); } } else { if (mediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, MovieAspect.ATTR_CERTIFICATION, null); } else if (mediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, SeriesAspect.ATTR_CERTIFICATION, null); } } } } }
public override async Task <ICollection <FilterValue> > GetAvailableValuesAsync(IEnumerable <Guid> necessaryMIATypeIds, IFilter selectAttributeFilter, IFilter filter) { IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (cd == null) { throw new NotConnectedException("The MediaLibrary is not connected"); } bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(necessaryMIATypeIds); if (string.IsNullOrEmpty(CertificationHelper.DisplayMovieCertificationCountry)) { HomogenousMap valueGroups = await cd.GetValueGroupsAsync(MovieAspect.ATTR_CERTIFICATION, null, ProjectionFunction.None, necessaryMIATypeIds, filter, true, showVirtual); IList <FilterValue> result = new List <FilterValue>(valueGroups.Count); int numEmptyEntries = 0; foreach (KeyValuePair <object, object> group in valueGroups) { string certification = (string)group.Key; if (!string.IsNullOrEmpty(certification)) { CertificationMapping cert; if (CertificationMapper.TryFindMovieCertification(certification, out cert)) { result.Add(new FilterValue(cert.CertificationId, cert.Name, new RelationalFilter(MovieAspect.ATTR_CERTIFICATION, RelationalOperator.EQ, certification), null, (int)group.Value, this)); } } else { numEmptyEntries += (int)group.Value; } } if (numEmptyEntries > 0) { result.Insert(0, new FilterValue("UR", Consts.RES_VALUE_UNRATED_TITLE, new EmptyFilter(MovieAspect.ATTR_CERTIFICATION), null, numEmptyEntries, this)); } return(result); } else { IList <FilterValue> result = new List <FilterValue>(); IFilter emptyFilter = new EmptyFilter(MovieAspect.ATTR_CERTIFICATION); int numEmptyItems = await cd.CountMediaItemsAsync(necessaryMIATypeIds, BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, emptyFilter), true, showVirtual); if (numEmptyItems > 0) { result.Add(new FilterValue("UR", Consts.RES_VALUE_UNRATED_TITLE, emptyFilter, null, numEmptyItems, this)); } List <string> usedFilters = new List <string>(); foreach (var cert in CertificationMapper.GetMovieCertificationsForCountry(CertificationHelper.DisplayMovieCertificationCountry)) { IEnumerable <CertificationMapping> certs = CertificationMapper.FindAllAllowedMovieCertifications(cert.CertificationId); if (certs.Count() > 0) { List <string> certList = new List <string>(certs.Select(c => c.CertificationId).Except(usedFilters)); usedFilters.AddRange(certList); IFilter certFilter = new InFilter(MovieAspect.ATTR_CERTIFICATION, certList); int numItems = await cd.CountMediaItemsAsync(necessaryMIATypeIds, BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, certFilter), true, showVirtual); result.Add(new FilterValue(cert.CertificationId, cert.Name, certFilter, null, numItems, this)); } } return(result); } }
public override async Task <bool> UpdateFromOnlineSeriesAsync(SeriesInfo series, TvdbLanguage language, bool cacheOnly) { try { language = language ?? PreferredLanguage; TvdbSeries seriesDetail = null; if (series.TvdbId > 0) { seriesDetail = await _tvdbHandler.GetSeriesAsync(series.TvdbId, language, true, true, false).ConfigureAwait(false); } if (seriesDetail == null && !cacheOnly && !string.IsNullOrEmpty(series.ImdbId)) { TvdbSearchResult foundSeries = await _tvdbHandler.GetSeriesByRemoteIdAsync(ExternalId.ImdbId, series.ImdbId).ConfigureAwait(false); if (foundSeries != null) { seriesDetail = await _tvdbHandler.GetSeriesAsync(foundSeries.Id, language, true, true, false).ConfigureAwait(false); } } if (seriesDetail == null) { return(false); } series.TvdbId = seriesDetail.Id; series.ImdbId = seriesDetail.ImdbId; series.SeriesName = new SimpleTitle(seriesDetail.SeriesName, false); series.FirstAired = seriesDetail.FirstAired; series.Description = new SimpleTitle(seriesDetail.Overview, false); series.Rating = new SimpleRating(seriesDetail.Rating, seriesDetail.RatingCount); series.Genres = seriesDetail.Genre.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(); series.Networks = ConvertToCompanies(seriesDetail.NetworkID, seriesDetail.Network, CompanyAspect.COMPANY_TV_NETWORK); if (seriesDetail.Status.IndexOf("Ended", StringComparison.InvariantCultureIgnoreCase) >= 0) { series.IsEnded = true; } CertificationMapping certification = null; if (CertificationMapper.TryFindMovieCertification(seriesDetail.ContentRating, out certification)) { series.Certification = certification.CertificationId; } series.Actors = ConvertToPersons(seriesDetail.TvdbActors, PersonAspect.OCCUPATION_ACTOR, null, seriesDetail.SeriesName); series.Characters = ConvertToCharacters(seriesDetail.TvdbActors, null, seriesDetail.SeriesName); foreach (TvdbActor actor in seriesDetail.TvdbActors) { _seriesToActorMap.StoreMappedId(actor.Id.ToString(), seriesDetail.Id.ToString()); } foreach (TvdbEpisode episodeDetail in seriesDetail.Episodes.OrderByDescending(e => e.Id)) { SeasonInfo seasonInfo = new SeasonInfo() { TvdbId = episodeDetail.SeasonId, SeriesTvdbId = seriesDetail.Id, SeriesImdbId = seriesDetail.ImdbId, SeriesName = new SimpleTitle(seriesDetail.SeriesName, false), SeasonNumber = episodeDetail.SeasonNumber, }; if (!series.Seasons.Contains(seasonInfo)) { series.Seasons.Add(seasonInfo); } EpisodeInfo episodeInfo = new EpisodeInfo() { TvdbId = episodeDetail.Id, SeriesTvdbId = seriesDetail.Id, SeriesImdbId = seriesDetail.ImdbId, SeriesName = new SimpleTitle(seriesDetail.SeriesName, false), SeriesFirstAired = seriesDetail.FirstAired, ImdbId = episodeDetail.ImdbId, SeasonNumber = episodeDetail.SeasonNumber, EpisodeNumbers = new List <int>(new int[] { episodeDetail.EpisodeNumber }), FirstAired = episodeDetail.FirstAired, EpisodeName = new SimpleTitle(episodeDetail.EpisodeName, false), Summary = new SimpleTitle(episodeDetail.Overview, false), Genres = seriesDetail.Genre.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(), Rating = new SimpleRating(episodeDetail.Rating, episodeDetail.RatingCount), }; if (episodeDetail.DvdEpisodeNumber > 0) { episodeInfo.DvdEpisodeNumbers = new List <double>(new double[] { episodeDetail.DvdEpisodeNumber }); } episodeInfo.Actors = ConvertToPersons(seriesDetail.TvdbActors, PersonAspect.OCCUPATION_ACTOR, episodeDetail.EpisodeName, seriesDetail.SeriesName); //info.Actors.AddRange(ConvertToPersons(episodeDetail.GuestStars, PersonAspect.OCCUPATION_ACTOR, info.Actors.Count)); episodeInfo.Characters = ConvertToCharacters(seriesDetail.TvdbActors, episodeDetail.EpisodeName, seriesDetail.SeriesName); episodeInfo.Directors = ConvertToPersons(episodeDetail.Directors, PersonAspect.OCCUPATION_DIRECTOR, 0, episodeDetail.EpisodeName, seriesDetail.SeriesName); episodeInfo.Writers = ConvertToPersons(episodeDetail.Writer, PersonAspect.OCCUPATION_WRITER, 0, episodeDetail.EpisodeName, seriesDetail.SeriesName); episodeInfo.Languages.Add(episodeDetail.Language.Abbriviation); if (!series.Episodes.Contains(episodeInfo)) { series.Episodes.Add(episodeInfo); } } series.Episodes.Sort(); series.TotalEpisodes = series.Episodes.Count; for (int index = 0; index < series.Seasons.Count; index++) { series.Seasons[index].FirstAired = series.Episodes.Find(e => e.SeasonNumber == series.Seasons[index].SeasonNumber).FirstAired; series.Seasons[index].TotalEpisodes = series.Episodes.FindAll(e => e.SeasonNumber == series.Seasons[index].SeasonNumber).Count; } series.Seasons.Sort(); series.TotalSeasons = series.Seasons.Count; TvdbEpisode nextEpisode = seriesDetail.Episodes.Where(e => e.FirstAired > DateTime.Now).OrderBy(e => e.FirstAired) .ThenByDescending(p => p.Id).FirstOrDefault(); if (nextEpisode != null) { series.NextEpisodeName = new SimpleTitle(nextEpisode.EpisodeName, false); series.NextEpisodeAirDate = nextEpisode.FirstAired; series.NextEpisodeSeasonNumber = nextEpisode.SeasonNumber; series.NextEpisodeNumber = nextEpisode.EpisodeNumber; } return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("TvDbWrapper: Exception while processing series {0}", ex, series.ToString()); return(false); } }
public static IEnumerable <MediaItem> ProcessMediaItems(IEnumerable <MediaItem> mediaItems) { UserProfile userProfile = null; bool applyUserRestrictions = false; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser; applyUserRestrictions = userProfileDataManagement.ApplyUserRestriction; } int allowedAge = 5; bool includeParentalGuidedContent = false; bool includeUnratedContent = false; bool allowAllAges = true; if (userProfile != null && applyUserRestrictions) { foreach (var key in userProfile.AdditionalData) { foreach (var val in key.Value) { if (key.Key == UserDataKeysKnown.KEY_ALLOW_ALL_AGES) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { allowAllAges = Convert.ToInt32(allow) > 0; } } else if (key.Key == UserDataKeysKnown.KEY_ALLOWED_AGE) { string age = val.Value; if (!string.IsNullOrEmpty(age) && Convert.ToInt32(age) >= 0) { allowedAge = Convert.ToInt32(age); } } else if (key.Key == UserDataKeysKnown.KEY_INCLUDE_PARENT_GUIDED_CONTENT) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { includeParentalGuidedContent = Convert.ToInt32(allow) > 0; } } else if (key.Key == UserDataKeysKnown.KEY_INCLUDE_UNRATED_CONTENT) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { includeUnratedContent = Convert.ToInt32(allow) > 0; } } } } } List <MediaItem> allowedMedia = new List <MediaItem>(); foreach (var mediaItem in mediaItems) { string certification = null; CertificationMapping bestMatch = null; CertificationMapping mediaMatch = null; if (mediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID)) { if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, MovieAspect.ATTR_CERTIFICATION, out certification)) { if (applyUserRestrictions && !allowAllAges) { if (CertificationMapper.TryFindMovieCertification(certification, out mediaMatch)) { if (!CertificationMapper.IsAgeAllowed(mediaMatch, allowedAge, includeParentalGuidedContent)) { continue; } } if (certification == null && !includeUnratedContent) { continue; } } if (certification != null && !string.IsNullOrEmpty(DisplayMovieCertificationCountry)) { bestMatch = CertificationMapper.FindMatchingMovieCertification(DisplayMovieCertificationCountry, certification); } } } if (mediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID)) { if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, SeriesAspect.ATTR_CERTIFICATION, out certification)) { if (applyUserRestrictions && !allowAllAges) { if (CertificationMapper.TryFindSeriesCertification(certification, out mediaMatch)) { if (!CertificationMapper.IsAgeAllowed(mediaMatch, allowedAge, includeParentalGuidedContent)) { continue; } } if (certification == null && !includeUnratedContent) { continue; } } if (certification != null && !string.IsNullOrEmpty(DisplaySeriesCertificationCountry)) { bestMatch = CertificationMapper.FindMatchingSeriesCertification(DisplaySeriesCertificationCountry, certification); } } } //Assign new certification value if (bestMatch != null) { if (mediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, MovieAspect.ATTR_CERTIFICATION, bestMatch.CertificationId); } else if (mediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, SeriesAspect.ATTR_CERTIFICATION, bestMatch.CertificationId); } } else { if (applyUserRestrictions && !allowAllAges && !includeUnratedContent) { continue; } if (mediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, MovieAspect.ATTR_CERTIFICATION, null); } else if (mediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID)) { MediaItemAspect.SetAttribute <string>(mediaItem.Aspects, SeriesAspect.ATTR_CERTIFICATION, null); } } allowedMedia.Add(mediaItem); } return(allowedMedia); }
public static async Task <IFilter> GetUserCertificateFilter(IEnumerable <Guid> necessaryMias) { UserProfile userProfile = null; bool applyUserRestrictions = false; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser; applyUserRestrictions = userProfileDataManagement.ApplyUserRestriction; } if (userProfile == null || !applyUserRestrictions) { return(null); } ICollection <Share> shares = null; IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>(); IContentDirectory contentDirectory = serverConnectionManager.ContentDirectory; if (contentDirectory != null) { shares = await contentDirectory.GetSharesAsync(null, SharesFilter.All); } int? allowedAge = null; bool? includeParentalGuidedContent = null; bool? includeUnratedContent = null; bool allowAllShares = true; bool allowAllAges = true; List <IFilter> shareFilters = new List <IFilter>(); foreach (var key in userProfile.AdditionalData) { foreach (var val in key.Value) { if (key.Key == UserDataKeysKnown.KEY_ALLOW_ALL_SHARES) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { allowAllShares = Convert.ToInt32(allow) > 0; } } else if (key.Key == UserDataKeysKnown.KEY_ALLOWED_SHARE) { Guid shareId = new Guid(val.Value); if (shares == null || !shares.Where(s => s.ShareId == shareId).Any()) { continue; } shareFilters.Add(new LikeFilter(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, shares.Where(s => s.ShareId == shareId).First().BaseResourcePath + "%", null, true)); } else if (key.Key == UserDataKeysKnown.KEY_ALLOW_ALL_AGES) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { allowAllAges = Convert.ToInt32(allow) > 0; } } else if (key.Key == UserDataKeysKnown.KEY_ALLOWED_AGE) { string age = val.Value; if (!string.IsNullOrEmpty(age) && Convert.ToInt32(age) >= 0) { allowedAge = Convert.ToInt32(age); } } else if (key.Key == UserDataKeysKnown.KEY_INCLUDE_PARENT_GUIDED_CONTENT) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { includeParentalGuidedContent = Convert.ToInt32(allow) > 0; } } else if (key.Key == UserDataKeysKnown.KEY_INCLUDE_UNRATED_CONTENT) { string allow = val.Value; if (!string.IsNullOrEmpty(allow) && Convert.ToInt32(allow) >= 0) { includeUnratedContent = Convert.ToInt32(allow) > 0; } } } } List <IFilter> filters = new List <IFilter>(); // Shares filter if (allowAllShares == false) { if (shareFilters.Count > 0) { filters.Add(BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, shareFilters.ToArray())); } else { filters.Add(new RelationalFilter(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, RelationalOperator.EQ, "")); } } // Content filter if (allowedAge.HasValue && allowAllAges == false) { if (necessaryMias.Contains(MovieAspect.ASPECT_ID)) { IEnumerable <CertificationMapping> certs = CertificationMapper.GetMovieCertificationsForAge(allowedAge.Value, includeParentalGuidedContent ?? false); if (certs.Count() > 0) { if (!includeUnratedContent ?? false) { filters.Add(new InFilter(MovieAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId))); } else { filters.Add(BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new InFilter(MovieAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)), new EmptyFilter(MovieAspect.ATTR_CERTIFICATION))); } } else if (!includeUnratedContent ?? false) { filters.Add(new NotFilter(new EmptyFilter(MovieAspect.ATTR_CERTIFICATION))); } } else if (necessaryMias.Contains(SeriesAspect.ASPECT_ID)) { //TODO: Should series filters reset the share filter? Series have no share dependency IEnumerable <CertificationMapping> certs = CertificationMapper.GetSeriesCertificationsForAge(allowedAge.Value, includeParentalGuidedContent ?? false); if (certs.Count() > 0) { if (!includeUnratedContent ?? false) { filters.Add(new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId))); } else { filters.Add(BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)), new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION))); } } else if (!includeUnratedContent ?? false) { filters.Add(new NotFilter(new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION))); } } else if (necessaryMias.Contains(EpisodeAspect.ASPECT_ID)) { IEnumerable <CertificationMapping> certs = CertificationMapper.GetSeriesCertificationsForAge(allowedAge.Value, includeParentalGuidedContent ?? false); if (certs.Count() > 0) { if (!includeUnratedContent ?? false) { filters.Add(new FilteredRelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)))); } else { filters.Add(new FilteredRelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)), new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION)))); } } else if (!includeUnratedContent ?? false) { filters.Add(new FilteredRelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, new NotFilter(new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION)))); } } } if (filters.Count > 1) { return(BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filters.ToArray())); } else if (filters.Count > 0) { return(filters[0]); } return(null); }
public override async Task <bool> UpdateFromOnlineSeriesAsync(SeriesInfo series, string language, bool cacheOnly) { try { OmDbSeries seriesDetail = null; if (!string.IsNullOrEmpty(series.ImdbId)) { seriesDetail = await _omDbHandler.GetSeriesAsync(series.ImdbId, cacheOnly).ConfigureAwait(false); } if (seriesDetail == null) { return(false); } series.ImdbId = seriesDetail.ImdbID; series.SeriesName = new SimpleTitle(seriesDetail.Title, true); series.FirstAired = seriesDetail.Released; series.Description = new SimpleTitle(seriesDetail.Plot, true); if (seriesDetail.EndYear.HasValue) { series.IsEnded = true; } CertificationMapping cert = null; if (CertificationMapper.TryFindMovieCertification(seriesDetail.Rated, out cert)) { series.Certification = cert.CertificationId; } List <string> awards = new List <string>(); if (!string.IsNullOrEmpty(seriesDetail.Awards)) { if (seriesDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || seriesDetail.Awards.IndexOf(" Oscar", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Oscar"); } if (seriesDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || seriesDetail.Awards.IndexOf(" Golden Globe", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Golden Globe"); } series.Awards = awards.ToList(); } if (seriesDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.ImdbRating, seriesDetail.ImdbVotes)); } if (seriesDetail.TomatoRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.TomatoRating, seriesDetail.TomatoTotalReviews)); } if (seriesDetail.TomatoUserRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref series.Rating, new SimpleRating(seriesDetail.TomatoUserRating, seriesDetail.TomatoUserTotalReviews)); } series.Genres = seriesDetail.Genres.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (seriesDetail.Actors == null || seriesDetail.Actors.Count == 0) { series.Actors = ConvertToPersons(seriesDetail.Actors, PersonAspect.OCCUPATION_ACTOR, null, seriesDetail.Title); } //Episode listing is currently not optimal //OmDbSeason seasonDetails = null; //OmDbSeasonEpisode nextEpisode = null; //int seasonNumber = 1; //while (true) //{ // seasonDetails = _omDbHandler.GetSeriesSeason(series.ImdbId, seasonNumber, cacheOnly); // if (seasonDetails != null) // { // SeasonInfo seasonInfo = new SeasonInfo() // { // SeriesImdbId = seriesDetail.ImdbID, // SeriesName = new SimpleTitle(seriesDetail.Title, true), // SeasonNumber = seasonDetails.SeasonNumber, // FirstAired = seasonDetails.Episodes.First().Released, // TotalEpisodes = seasonDetails.Episodes.Count // }; // if (!series.Seasons.Contains(seasonInfo)) // series.Seasons.Add(seasonInfo); // foreach (OmDbSeasonEpisode episodeDetail in seasonDetails.Episodes) // { // if (episodeDetail.EpisodeNumber <= 0) continue; // EpisodeInfo info = new EpisodeInfo() // { // ImdbId = episodeDetail.ImdbID, // SeriesImdbId = seriesDetail.ImdbID, // SeriesName = new SimpleTitle(seriesDetail.Title, true), // SeriesFirstAired = series.FirstAired, // SeasonNumber = seasonNumber, // EpisodeNumbers = new List<int>(new int[] { episodeDetail.EpisodeNumber }), // FirstAired = episodeDetail.Released, // EpisodeName = new SimpleTitle(episodeDetail.Title, true), // }; // series.Episodes.Add(info); // if (nextEpisode == null && episodeDetail.Released > DateTime.Now) // { // series.NextEpisodeName = new SimpleTitle(episodeDetail.Title, true); // series.NextEpisodeAirDate = episodeDetail.Released; // series.NextEpisodeSeasonNumber = seasonDetails.SeasonNumber; // series.NextEpisodeNumber = episodeDetail.EpisodeNumber; // } // } // seasonNumber++; // } // else // { // break; // } //} series.TotalSeasons = series.Seasons.Count; series.TotalEpisodes = series.Episodes.Count; return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing series {0}", ex, series.ToString()); return(false); } }
public override async Task <bool> UpdateFromOnlineMovieAsync(MovieInfo movie, string language, bool cacheOnly) { try { OmDbMovie movieDetail = null; if (!string.IsNullOrEmpty(movie.ImdbId)) { movieDetail = await _omDbHandler.GetMovie(movie.ImdbId, cacheOnly).ConfigureAwait(false); } if (movieDetail == null) { return(false); } movie.ImdbId = movieDetail.ImdbID; movie.MovieName = new SimpleTitle(movieDetail.Title, true); movie.Summary = new SimpleTitle(movieDetail.Plot, true); CertificationMapping cert = null; if (CertificationMapper.TryFindMovieCertification(movieDetail.Rated, out cert)) { movie.Certification = cert.CertificationId; } movie.Revenue = movieDetail.Revenue.HasValue ? movieDetail.Revenue.Value : 0; movie.Runtime = movieDetail.Runtime.HasValue ? movieDetail.Runtime.Value : 0; movie.ReleaseDate = movieDetail.Released; List <string> awards = new List <string>(); if (!string.IsNullOrEmpty(movieDetail.Awards)) { if (movieDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || movieDetail.Awards.IndexOf(" Oscar", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Oscar"); } if (movieDetail.Awards.IndexOf("Won ", StringComparison.InvariantCultureIgnoreCase) >= 0 || movieDetail.Awards.IndexOf(" Golden Globe", StringComparison.InvariantCultureIgnoreCase) >= 0) { awards.Add("Golden Globe"); } movie.Awards = awards.ToList(); } if (movieDetail.ImdbRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.ImdbRating, movieDetail.ImdbVotes)); } if (movieDetail.TomatoRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.TomatoRating, movieDetail.TomatoTotalReviews)); } if (movieDetail.TomatoUserRating.HasValue) { MetadataUpdater.SetOrUpdateRatings(ref movie.Rating, new SimpleRating(movieDetail.TomatoUserRating, movieDetail.TomatoUserTotalReviews)); } movie.Genres = movieDetail.Genres.Where(s => !string.IsNullOrEmpty(s?.Trim())).Select(s => new GenreInfo { Name = s.Trim() }).ToList(); //Only use these if absolutely necessary because there is no way to ID them if (movie.Actors.Count == 0) { movie.Actors = ConvertToPersons(movieDetail.Actors, PersonAspect.OCCUPATION_ACTOR, movieDetail.Title); } if (movie.Writers.Count == 0) { movie.Writers = ConvertToPersons(movieDetail.Writers, PersonAspect.OCCUPATION_WRITER, movieDetail.Title); } if (movie.Directors.Count == 0) { movie.Directors = ConvertToPersons(movieDetail.Directors, PersonAspect.OCCUPATION_DIRECTOR, movieDetail.Title); } return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Debug("OmDbWrapper: Exception while processing movie {0}", ex, movie.ToString()); return(false); } }
public IFilter GetUserFilter(ICollection <Guid> necessaryMias, bool ignoreShareRestriction = false) { List <IFilter> filters = new List <IFilter>(); // Shares filter if (RestrictShares && !ignoreShareRestriction) { filters.Add(new SharePathFilter(GetAllowedShares())); } // Content filter if (AllowedAge.HasValue && RestrictAges) { if (necessaryMias.Contains(MovieAspect.ASPECT_ID)) { var certs = CertificationMapper.GetMovieCertificationsForAge(AllowedAge.Value, IncludeParentGuidedContent).ToList(); if (certs.Any()) { if (!IncludeUnratedContent) { filters.Add(new InFilter(MovieAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId))); } else { filters.Add(BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new InFilter(MovieAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)), new EmptyFilter(MovieAspect.ATTR_CERTIFICATION))); } } else if (!IncludeUnratedContent) { filters.Add(new NotFilter(new EmptyFilter(MovieAspect.ATTR_CERTIFICATION))); } } else if (necessaryMias.Contains(SeriesAspect.ASPECT_ID)) { //TODO: Should series filters reset the share filter? Series have no share dependency var certs = CertificationMapper.GetSeriesCertificationsForAge(AllowedAge.Value, IncludeParentGuidedContent).ToList(); if (certs.Any()) { if (!IncludeUnratedContent) { filters.Add(new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId))); } else { filters.Add(BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)), new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION))); } } else if (!IncludeUnratedContent) { filters.Add(new NotFilter(new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION))); } } else if (necessaryMias.Contains(EpisodeAspect.ASPECT_ID)) { var certs = CertificationMapper.GetSeriesCertificationsForAge(AllowedAge.Value, IncludeParentGuidedContent).ToList(); if (certs.Any()) { if (!IncludeUnratedContent) { filters.Add(new FilteredRelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)))); } else { filters.Add(new FilteredRelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new InFilter(SeriesAspect.ATTR_CERTIFICATION, certs.Select(c => c.CertificationId)), new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION)))); } } else if (!IncludeUnratedContent) { filters.Add(new FilteredRelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, new NotFilter(new EmptyFilter(SeriesAspect.ATTR_CERTIFICATION)))); } } } if (filters.Count > 1) { return(BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filters.ToArray())); } else if (filters.Count > 0) { return(filters[0]); } return(null); }