예제 #1
0
        private InternalItemsQuery GetItemsQuery(GetQueryFilters request, User user)
        {
            var query = new InternalItemsQuery
            {
                User             = user,
                MediaTypes       = request.GetMediaTypes(),
                IncludeItemTypes = request.GetIncludeItemTypes(),
                Recursive        = true
            };

            return(query);
        }
예제 #2
0
        public async Task <object> Get(GetQueryFilters request)
        {
            var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId);
            var user       = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.ParentId) ?
                       user == null ? _libraryManager.RootFolder : user.RootFolder :
                       parentItem;

            var result = await((Folder)item).GetItems(GetItemsQuery(request, user));

            return(ToOptimizedResult(GetFilters(result.Items)));
        }
예제 #3
0
        private InternalItemsQuery GetItemsQuery(GetQueryFilters request, User user)
        {
            var query = new InternalItemsQuery
            {
                User                   = user,
                MediaTypes             = request.GetMediaTypes(),
                IncludeItemTypes       = request.GetIncludeItemTypes(),
                Recursive              = true,
                EnableTotalRecordCount = false,
                DtoOptions             = new Controller.Dto.DtoOptions
                {
                    Fields         = new ItemFields[] { ItemFields.Genres, ItemFields.Tags },
                    EnableImages   = false,
                    EnableUserData = false
                }
            };

            return(query);
        }
        public object Get(GetQueryFilters request)
        {
            var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId);
            var user       = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(request.IncludeItemTypes, typeof(Trailer).Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(request.IncludeItemTypes, "Program", StringComparison.OrdinalIgnoreCase))
            {
                parentItem = null;
            }

            var filters = new QueryFilters();

            var genreQuery = new InternalItemsQuery(user)
            {
                IncludeItemTypes = request.GetIncludeItemTypes(),
                DtoOptions       = new Controller.Dto.DtoOptions
                {
                    Fields         = new ItemFields[] { },
                    EnableImages   = false,
                    EnableUserData = false
                },
                IsAiring = request.IsAiring,
                IsMovie  = request.IsMovie,
                IsSports = request.IsSports,
                IsKids   = request.IsKids,
                IsNews   = request.IsNews,
                IsSeries = request.IsSeries
            };

            // Non recursive not yet supported for library folders
            if ((request.Recursive ?? true) || parentItem is UserView || parentItem is ICollectionFolder)
            {
                genreQuery.AncestorIds = parentItem == null?Array.Empty <Guid>() : new Guid[]
                {
                    parentItem.Id
                };
            }
            else
            {
                genreQuery.Parent = parentItem;
            }

            if (string.Equals(request.IncludeItemTypes, "MusicAlbum", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(request.IncludeItemTypes, "MusicVideo", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(request.IncludeItemTypes, "MusicArtist", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(request.IncludeItemTypes, "Audio", StringComparison.OrdinalIgnoreCase))
            {
                filters.Genres = _libraryManager.GetMusicGenres(genreQuery).Items.Select(i => new NameIdPair
                {
                    Name = i.Item1.Name,
                    Id   = i.Item1.Id.ToString("N")
                }).ToArray();
            }
            else if (string.Equals(request.IncludeItemTypes, "Game", StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(request.IncludeItemTypes, "GameSystem", StringComparison.OrdinalIgnoreCase))
            {
                filters.Genres = _libraryManager.GetGameGenres(genreQuery).Items.Select(i => new NameIdPair
                {
                    Name = i.Item1.Name,
                    Id   = i.Item1.Id.ToString("N")
                }).ToArray();
            }
            else
            {
                filters.Genres = _libraryManager.GetGenres(genreQuery).Items.Select(i => new NameIdPair
                {
                    Name = i.Item1.Name,
                    Id   = i.Item1.Id.ToString("N")
                }).ToArray();
            }

            return(ToOptimizedResult(filters));
        }