コード例 #1
0
        public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user, List <ItemFields> fields)
        {
            if (!SupportsUserDataFromChildren)
            {
                return;
            }

            if (itemDto != null)
            {
                if (fields.Contains(ItemFields.RecursiveItemCount))
                {
                    itemDto.RecursiveItemCount = GetRecursiveChildCount(user);
                }
            }

            if (SupportsPlayedStatus)
            {
                var unplayedQueryResult = GetItems(new InternalItemsQuery(user)
                {
                    Recursive              = true,
                    IsFolder               = false,
                    IsVirtualItem          = false,
                    EnableTotalRecordCount = true,
                    Limit      = 0,
                    IsPlayed   = false,
                    DtoOptions = new DtoOptions(false)
                    {
                        EnableImages = false
                    }
                });

                double unplayedCount = unplayedQueryResult.TotalRecordCount;

                dto.UnplayedItemCount = unplayedQueryResult.TotalRecordCount;

                if (itemDto != null && itemDto.RecursiveItemCount.HasValue)
                {
                    if (itemDto.RecursiveItemCount.Value > 0)
                    {
                        var unplayedPercentage = (unplayedCount / itemDto.RecursiveItemCount.Value) * 100;
                        dto.PlayedPercentage = 100 - unplayedPercentage;
                        dto.Played           = dto.PlayedPercentage.Value >= 100;
                    }
                }
                else
                {
                    dto.Played = (dto.UnplayedItemCount ?? 0) == 0;
                }
            }
        }
コード例 #2
0
        public override async Task FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user)
        {
            if (!SupportsUserDataFromChildren)
            {
                return;
            }

            var unplayedQueryResult = await GetItems(new InternalItemsQuery(user)
            {
                Recursive              = true,
                IsFolder               = false,
                IsVirtualItem          = false,
                EnableTotalRecordCount = true,
                Limit    = 0,
                IsPlayed = false
            }).ConfigureAwait(false);

            var allItemsQueryResult = await GetItems(new InternalItemsQuery(user)
            {
                Recursive              = true,
                IsFolder               = false,
                IsVirtualItem          = false,
                EnableTotalRecordCount = true,
                Limit = 0
            }).ConfigureAwait(false);

            if (itemDto != null)
            {
                itemDto.RecursiveItemCount = allItemsQueryResult.TotalRecordCount;
            }

            var    recursiveItemCount = allItemsQueryResult.TotalRecordCount;
            double unplayedCount      = unplayedQueryResult.TotalRecordCount;

            if (recursiveItemCount > 0)
            {
                var unplayedPercentage = (unplayedCount / recursiveItemCount) * 100;
                dto.PlayedPercentage  = 100 - unplayedPercentage;
                dto.Played            = dto.PlayedPercentage.Value >= 100;
                dto.UnplayedItemCount = unplayedQueryResult.TotalRecordCount;
            }

            if (itemDto != null)
            {
                if (this is Season || this is MusicAlbum)
                {
                    itemDto.ChildCount = recursiveItemCount;
                }
            }
        }
コード例 #3
0
ファイル: UserRootFolder.cs プロジェクト: webcris77/Emby
 public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, User user)
 {
     // Nothing meaninful here and will only waste resources
 }
コード例 #4
0
        public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, User user)
        {
            var recursiveItemCount = 0;
            var unplayed           = 0;

            double totalPercentPlayed = 0;

            IEnumerable <BaseItem> children;
            var folder = this;

            var season = folder as Season;

            if (season != null)
            {
                children = season.GetEpisodes(user).Where(i => i.LocationType != LocationType.Virtual);
            }
            else
            {
                children = folder.GetRecursiveChildren(user, i => !i.IsFolder && i.LocationType != LocationType.Virtual);
            }

            // Loop through each recursive child
            foreach (var child in children)
            {
                recursiveItemCount++;

                var isUnplayed = true;

                var itemUserData = UserDataManager.GetUserData(user.Id, child.GetUserDataKey());

                // Incrememt totalPercentPlayed
                if (itemUserData != null)
                {
                    if (itemUserData.Played)
                    {
                        totalPercentPlayed += 100;

                        isUnplayed = false;
                    }
                    else if (itemUserData.PlaybackPositionTicks > 0 && child.RunTimeTicks.HasValue && child.RunTimeTicks.Value > 0)
                    {
                        double itemPercent = itemUserData.PlaybackPositionTicks;
                        itemPercent        /= child.RunTimeTicks.Value;
                        totalPercentPlayed += itemPercent;
                    }
                }

                if (isUnplayed)
                {
                    unplayed++;
                }
            }

            dto.UnplayedItemCount = unplayed;

            if (recursiveItemCount > 0)
            {
                dto.PlayedPercentage = totalPercentPlayed / recursiveItemCount;
                dto.Played           = dto.PlayedPercentage.Value >= 100;
            }
        }
コード例 #5
0
        private static void SetData(Played played)
        {
            if (played == null)
            {
                return;
            }

            if (played.Data == null)
            {
                return;
            }

            UserItemDataDto userData = null;

            if (played.Data is BaseItemDto)
            {
                var item = played.Data as BaseItemDto;
                var type = item.Type;
                if (type != "Season" && type != "Series" && type != "BoxSet" && item.MediaType != "Video" && item.Type != "MusicAlbum" && item.Type != "MusicArtist")
                {
                    if (played._unwatchedGrid != null && played._theEllipse != null && played._watchedPath != null)
                    {
                        played._unwatchedGrid.Visibility = item.UserData != null && item.UserData.UnplayedItemCount.HasValue && item.UserData.UnplayedItemCount.Value > 0 ? Visibility.Visible : Visibility.Collapsed;
                        played._theEllipse.Visibility    = played._unwatchedGrid.Visibility;

                        if (item.UserData != null)
                        {
                            played._watchedPath.Visibility = item.UserData.Played ? Visibility.Visible : Visibility.Collapsed;
                        }
                        else
                        {
                            played._watchedPath.Visibility = Visibility.Collapsed;
                        }
                    }
                    return;
                }

                if (item.MediaType == null || item.MediaType != "Video")
                {
                    if (played._unwatchedGrid != null && played._watchedPath != null && played._theEllipse != null)
                    {
                        played._unwatchedGrid.Visibility = item.UserData != null && item.UserData.UnplayedItemCount.HasValue && item.UserData.UnplayedItemCount.Value > 0
                            ? Visibility.Visible
                            : Visibility.Collapsed;

                        played._watchedPath.Visibility = item.UserData != null && item.UserData.Played
                            ? Visibility.Visible
                            : Visibility.Collapsed;

                        played._theEllipse.Visibility = (played._unwatchedGrid.Visibility == Visibility.Visible ||
                                                         played._watchedPath.Visibility == Visibility.Visible)
                            ? Visibility.Visible
                            : Visibility.Collapsed;
                    }

                    return;
                }
                userData = item.UserData;
            }

            if (played._unwatchedGrid != null && played._theEllipse != null)
            {
                played._unwatchedGrid.Visibility = Visibility.Collapsed;
                played._theEllipse.Visibility    = Visibility.Collapsed;
            }

            if (played._watchedPath != null && played._theEllipse != null && userData != null)
            {
                played._watchedPath.Visibility = userData.Played ? Visibility.Visible : Visibility.Collapsed;
                played._theEllipse.Visibility  = played._watchedPath.Visibility;
            }
        }