Пример #1
0
        protected static async Task NotifyPlayback(MediaItem mediaItem, int playPercentage, double playDuration)
        {
            ISettingsManager      settingsManager = ServiceRegistration.Get <ISettingsManager>();
            PlayerManagerSettings settings        = settingsManager.Load <PlayerManagerSettings>();
            bool watched = playPercentage >= settings.WatchedPlayPercentage;

            if (watched && mediaItem.IsLastPart)
            {
                playPercentage = 100;
            }
            else if (watched && !mediaItem.IsLastPart)
            {
                playPercentage = 50;
            }

            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;

            if (cd != null)
            {
                IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();
                if (userProfileDataManagement.IsValidUser)
                {
                    bool updatePlayDate = (watched || playDuration >= MINIMUM_WATCHED_SEC || playPercentage >= MINIMUM_WATCHED_PERCENT);
                    await cd.NotifyUserPlaybackAsync(userProfileDataManagement.CurrentUser.ProfileId, mediaItem.MediaItemId, playPercentage, updatePlayDate);
                }
                else
                {
                    await cd.NotifyPlaybackAsync(mediaItem.MediaItemId, watched);
                }
            }

            // Update loaded item also, so changes will be visible in GUI without reloading
            if (!mediaItem.UserData.ContainsKey(UserDataKeysKnown.KEY_PLAY_PERCENTAGE))
            {
                mediaItem.UserData.Add(UserDataKeysKnown.KEY_PLAY_PERCENTAGE, "0");
            }
            mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_PERCENTAGE] = UserDataKeysKnown.GetSortablePlayPercentageString(playPercentage);

            if (watched)
            {
                // Update loaded item also, so changes will be visible in GUI without reloading
                int currentPlayCount;
                if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, 0, out currentPlayCount))
                {
                    MediaItemAspect.SetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, ++currentPlayCount);
                }

                if (!mediaItem.UserData.ContainsKey(UserDataKeysKnown.KEY_PLAY_COUNT))
                {
                    mediaItem.UserData.Add(UserDataKeysKnown.KEY_PLAY_COUNT, UserDataKeysKnown.GetSortablePlayCountString(0));
                }
                currentPlayCount = Convert.ToInt32(mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT]);
                currentPlayCount++;
                mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT] = UserDataKeysKnown.GetSortablePlayCountString(currentPlayCount);
            }
            ContentDirectoryMessaging.SendMediaItemChangedMessage(mediaItem, ContentDirectoryMessaging.MediaItemChangeType.Updated);
        }
        protected override async Task <MediaItemQuery> CreateQueryAsync()
        {
            Guid?   userProfile  = CurrentUserProfile?.ProfileId;
            IFilter linkedFilter = userProfile.HasValue ? BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                                                  new NotFilter(new EmptyUserDataFilter(userProfile.Value, UserDataKeysKnown.KEY_PLAY_COUNT)),
                                                                                                  new RelationalUserDataFilter(userProfile.Value, UserDataKeysKnown.KEY_PLAY_COUNT, RelationalOperator.GT, UserDataKeysKnown.GetSortablePlayCountString(0))) :
                                   null;
            IFilter filter = userProfile.HasValue ? BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                                            new FilteredRelationshipFilter(_role, _linkedRole, await AppendUserFilterAsync(linkedFilter, _necessaryLinkedMias)),
                                                                                            new NotFilter(new EmptyUserDataFilter(userProfile.Value, UserDataKeysKnown.KEY_PLAY_MAX_CHILD_COUNT))) :
                             new RelationalFilter(MediaAspect.ATTR_PLAYCOUNT, RelationalOperator.GT, 0);

            List <ISortInformation> sort = userProfile.HasValue ? new List <ISortInformation>
            {
                new DataSortInformation(UserDataKeysKnown.KEY_PLAY_MAX_CHILD_COUNT, SortDirection.Descending),
                new DataSortInformation(UserDataKeysKnown.KEY_PLAY_COUNT, SortDirection.Descending),
                new DataSortInformation(UserDataKeysKnown.KEY_PLAY_DATE, SortDirection.Descending)
            } :
            new List <ISortInformation>
            {
                new AttributeSortInformation(MediaAspect.ATTR_PLAYCOUNT, SortDirection.Descending),
                new AttributeSortInformation(MediaAspect.ATTR_LASTPLAYED, SortDirection.Descending)
            };

            return(new MediaItemQuery(_necessaryMias, _optionalMias, filter)
            {
                SubqueryFilter = GetNavigationFilter(_navigationInitializerType),
                SortInformation = sort
            });
        }