Ejemplo n.º 1
0
        protected ItemsResult GetResultSlim(GetItemsByName request)
        {
            var dtoOptions = GetDtoOptions(request);

            User     user = null;
            BaseItem parentItem;

            if (!string.IsNullOrWhiteSpace(request.UserId))
            {
                user       = UserManager.GetUserById(request.UserId);
                parentItem = string.IsNullOrEmpty(request.ParentId) ? user.RootFolder : LibraryManager.GetItemById(request.ParentId);
            }
            else
            {
                parentItem = string.IsNullOrEmpty(request.ParentId) ? LibraryManager.RootFolder : LibraryManager.GetItemById(request.ParentId);
            }

            var excludeItemTypes = request.GetExcludeItemTypes();
            var includeItemTypes = request.GetIncludeItemTypes();
            var mediaTypes       = request.GetMediaTypes();

            var query = new InternalItemsQuery(user)
            {
                ExcludeItemTypes               = excludeItemTypes,
                IncludeItemTypes               = includeItemTypes,
                MediaTypes                     = mediaTypes,
                StartIndex                     = request.StartIndex,
                Limit                          = request.Limit,
                IsFavorite                     = request.IsFavorite,
                NameLessThan                   = request.NameLessThan,
                NameStartsWith                 = request.NameStartsWith,
                NameStartsWithOrGreater        = request.NameStartsWithOrGreater,
                AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater,
                Tags               = request.GetTags(),
                OfficialRatings    = request.GetOfficialRatings(),
                Genres             = request.GetGenres(),
                GenreIds           = request.GetGenreIds(),
                Studios            = request.GetStudios(),
                StudioIds          = request.GetStudioIds(),
                Person             = request.Person,
                PersonIds          = request.GetPersonIds(),
                PersonTypes        = request.GetPersonTypes(),
                Years              = request.GetYears(),
                MinCommunityRating = request.MinCommunityRating
            };

            if (!string.IsNullOrWhiteSpace(request.ParentId))
            {
                if (parentItem is Folder)
                {
                    query.AncestorIds = new[] { request.ParentId };
                }
                else
                {
                    query.ItemIds = new[] { request.ParentId };
                }
            }

            foreach (var filter in request.GetFilters())
            {
                switch (filter)
                {
                case ItemFilter.Dislikes:
                    query.IsLiked = false;
                    break;

                case ItemFilter.IsFavorite:
                    query.IsFavorite = true;
                    break;

                case ItemFilter.IsFavoriteOrLikes:
                    query.IsFavoriteOrLiked = true;
                    break;

                case ItemFilter.IsFolder:
                    query.IsFolder = true;
                    break;

                case ItemFilter.IsNotFolder:
                    query.IsFolder = false;
                    break;

                case ItemFilter.IsPlayed:
                    query.IsPlayed = true;
                    break;

                case ItemFilter.IsRecentlyAdded:
                    break;

                case ItemFilter.IsResumable:
                    query.IsResumable = true;
                    break;

                case ItemFilter.IsUnplayed:
                    query.IsPlayed = false;
                    break;

                case ItemFilter.Likes:
                    query.IsLiked = true;
                    break;
                }
            }

            var result = GetItems(request, query);

            var syncProgess = DtoService.GetSyncedItemProgress(dtoOptions);
            var dtos        = result.Items.Select(i =>
            {
                var dto = DtoService.GetItemByNameDto(i.Item1, dtoOptions, null, syncProgess, user);

                if (!string.IsNullOrWhiteSpace(request.IncludeItemTypes))
                {
                    SetItemCounts(dto, i.Item2);
                }
                return(dto);
            });

            return(new ItemsResult
            {
                Items = dtos.ToArray(),
                TotalRecordCount = result.TotalRecordCount
            });
        }