Пример #1
0
        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);
                        }
                    }
                }
            }
        }
Пример #2
0
        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);
        }