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
            });
        }
Ejemplo n.º 2
0
        protected QueryResult <BaseItemDto> GetResultSlim(GetItemsByName request)
        {
            var dtoOptions = GetDtoOptions(AuthorizationContext, request);

            User     user = null;
            BaseItem parentItem;

            if (!request.UserId.Equals(Guid.Empty))
            {
                user       = UserManager.GetUserById(request.UserId);
                parentItem = string.IsNullOrEmpty(request.ParentId) ? LibraryManager.GetUserRootFolder() : 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,
                Tags                   = request.GetTags(),
                OfficialRatings        = request.GetOfficialRatings(),
                Genres                 = request.GetGenres(),
                GenreIds               = GetGuids(request.GenreIds),
                StudioIds              = GetGuids(request.StudioIds),
                Person                 = request.Person,
                PersonIds              = GetGuids(request.PersonIds),
                PersonTypes            = request.GetPersonTypes(),
                Years                  = request.GetYears(),
                MinCommunityRating     = request.MinCommunityRating,
                DtoOptions             = dtoOptions,
                SearchTerm             = request.SearchTerm,
                EnableTotalRecordCount = request.EnableTotalRecordCount
            };

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

            // Studios
            if (!string.IsNullOrEmpty(request.Studios))
            {
                query.StudioIds = request.Studios.Split('|').Select(i =>
                {
                    try
                    {
                        return(LibraryManager.GetStudio(i));
                    }
                    catch
                    {
                        return(null);
                    }
                }).Where(i => i != null).Select(i => i.Id).ToArray();
            }

            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.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 dtos = result.Items.Select(i =>
            {
                var dto = DtoService.GetItemByNameDto(i.Item1, dtoOptions, null, user);

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

            return(new QueryResult <BaseItemDto>
            {
                Items = dtos.ToArray(),
                TotalRecordCount = result.TotalRecordCount
            });
        }