Ejemplo n.º 1
0
        public object Get(GetEpisodes request)
        {
            var user = _userManager.GetUserById(request.UserId);

            List <BaseItem> episodes;

            var dtoOptions = GetDtoOptions(_authContext, request);

            if (!string.IsNullOrWhiteSpace(request.SeasonId))
            {
                var season = _libraryManager.GetItemById(new Guid(request.SeasonId)) as Season;

                if (season == null)
                {
                    throw new ResourceNotFoundException("No season exists with Id " + request.SeasonId);
                }

                episodes = season.GetEpisodes(user, dtoOptions);
            }
            else if (request.Season.HasValue)
            {
                var series = GetSeries(request.Id, user);

                if (series == null)
                {
                    throw new ResourceNotFoundException("Series not found");
                }

                var season = series.GetSeasons(user, dtoOptions).FirstOrDefault(i => i.IndexNumber == request.Season.Value);

                if (season == null)
                {
                    episodes = new List <BaseItem>();
                }
                else
                {
                    episodes = ((Season)season).GetEpisodes(user, dtoOptions);
                }
            }
            else
            {
                var series = GetSeries(request.Id, user);

                if (series == null)
                {
                    throw new ResourceNotFoundException("Series not found");
                }

                episodes = series.GetEpisodes(user, dtoOptions).ToList();
            }

            // Filter after the fact in case the ui doesn't want them
            if (request.IsMissing.HasValue)
            {
                var val = request.IsMissing.Value;
                episodes = episodes.Where(i => ((Episode)i).IsMissingEpisode == val).ToList();
            }

            if (!string.IsNullOrWhiteSpace(request.StartItemId))
            {
                episodes = episodes.SkipWhile(i => !string.Equals(i.Id.ToString("N", CultureInfo.InvariantCulture), request.StartItemId, StringComparison.OrdinalIgnoreCase)).ToList();
            }

            // This must be the last filter
            if (!string.IsNullOrEmpty(request.AdjacentTo))
            {
                episodes = UserViewBuilder.FilterForAdjacency(episodes, request.AdjacentTo).ToList();
            }

            if (string.Equals(request.SortBy, ItemSortBy.Random, StringComparison.OrdinalIgnoreCase))
            {
                episodes.Shuffle();
            }

            var returnItems = episodes;

            if (request.StartIndex.HasValue || request.Limit.HasValue)
            {
                returnItems = ApplyPaging(episodes, request.StartIndex, request.Limit).ToList();
            }

            var dtos = _dtoService.GetBaseItemDtos(returnItems, dtoOptions, user);

            return(new QueryResult <BaseItemDto>
            {
                TotalRecordCount = episodes.Count,
                Items = dtos
            });
        }
Ejemplo n.º 2
0
        public object Get(GetEpisodes request)
        {
            var user = _userManager.GetUserById(request.UserId);

            IEnumerable <Episode> episodes;

            if (string.IsNullOrEmpty(request.SeasonId))
            {
                var series = _libraryManager.GetItemById(request.Id) as Series;

                if (series == null)
                {
                    throw new ResourceNotFoundException("No series exists with Id " + request.Id);
                }

                episodes = series.GetEpisodes(user, request.Season.Value);
            }
            else
            {
                var season = _libraryManager.GetItemById(new Guid(request.SeasonId)) as Season;

                if (season == null)
                {
                    throw new ResourceNotFoundException("No season exists with Id " + request.SeasonId);
                }

                episodes = season.GetEpisodes(user);
            }

            // Filter after the fact in case the ui doesn't want them
            if (request.IsMissing.HasValue)
            {
                var val = request.IsMissing.Value;
                episodes = episodes.Where(i => i.IsMissingEpisode == val);
            }

            // Filter after the fact in case the ui doesn't want them
            if (request.IsVirtualUnaired.HasValue)
            {
                var val = request.IsVirtualUnaired.Value;
                episodes = episodes.Where(i => i.IsVirtualUnaired == val);
            }

            // This must be the last filter
            if (!string.IsNullOrEmpty(request.AdjacentTo))
            {
                episodes = ItemsService.FilterForAdjacency(episodes, request.AdjacentTo)
                           .Cast <Episode>();
            }

            var fields = request.GetItemFields().ToList();

            episodes = _libraryManager.ReplaceVideosWithPrimaryVersions(episodes).Cast <Episode>();

            var returnItems = episodes.Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                              .ToArray();

            return(new ItemsResult
            {
                TotalRecordCount = returnItems.Length,
                Items = returnItems
            });
        }
Ejemplo n.º 3
0
        public async Task <object> Get(GetEpisodes request)
        {
            var user = _userManager.GetUserById(request.UserId);

            IEnumerable <Episode> episodes;

            var dtoOptions = GetDtoOptions(_authContext, request);

            if (!string.IsNullOrWhiteSpace(request.SeasonId))
            {
                var season = _libraryManager.GetItemById(new Guid(request.SeasonId)) as Season;

                if (season == null)
                {
                    throw new ResourceNotFoundException("No season exists with Id " + request.SeasonId);
                }

                episodes = season.GetEpisodes(user, dtoOptions);
            }
            else if (request.Season.HasValue)
            {
                var series = GetSeries(request.Id, user);

                if (series == null)
                {
                    throw new ResourceNotFoundException("Series not found");
                }

                var season = series.GetSeasons(user, dtoOptions).FirstOrDefault(i => i.IndexNumber == request.Season.Value);

                if (season == null)
                {
                    episodes = new List <Episode>();
                }
                else
                {
                    episodes = season.GetEpisodes(user, dtoOptions);
                }
            }
            else
            {
                var series = GetSeries(request.Id, user);

                if (series == null)
                {
                    throw new ResourceNotFoundException("Series not found");
                }

                episodes = series.GetEpisodes(user, dtoOptions);
            }

            // Filter after the fact in case the ui doesn't want them
            if (request.IsMissing.HasValue)
            {
                var val = request.IsMissing.Value;
                episodes = episodes.Where(i => i.IsMissingEpisode == val);
            }

            // Filter after the fact in case the ui doesn't want them
            if (request.IsVirtualUnaired.HasValue)
            {
                var val = request.IsVirtualUnaired.Value;
                episodes = episodes.Where(i => i.IsVirtualUnaired == val);
            }

            if (!string.IsNullOrWhiteSpace(request.StartItemId))
            {
                episodes = episodes.SkipWhile(i => !string.Equals(i.Id.ToString("N"), request.StartItemId, StringComparison.OrdinalIgnoreCase));
            }

            IEnumerable <BaseItem> returnItems = episodes;

            // This must be the last filter
            if (!string.IsNullOrEmpty(request.AdjacentTo))
            {
                returnItems = UserViewBuilder.FilterForAdjacency(returnItems, request.AdjacentTo);
            }

            var returnList = returnItems.ToList();

            var pagedItems = ApplyPaging(returnList, request.StartIndex, request.Limit);

            var dtos = (await _dtoService.GetBaseItemDtos(pagedItems, dtoOptions, user).ConfigureAwait(false))
                       .ToArray();

            return(new ItemsResult
            {
                TotalRecordCount = returnList.Count,
                Items = dtos
            });
        }