Esempio n. 1
0
        private object GetResult(IEnumerable <Audio> items, User user, BaseGetSimilarItems request)
        {
            var list = items.ToList();

            var result = new ItemsResult
            {
                TotalRecordCount = list.Count
            };

            var dtoOptions = GetDtoOptions(request);

            result.Items = _dtoService.GetBaseItemDtos(list.Take(request.Limit ?? list.Count), dtoOptions, user).ToArray();

            return(ToOptimizedResult(result));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the items.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{ItemsResult}.</returns>
        private async Task <ItemsResult> GetItems(GetItems request)
        {
            var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId);
            var user       = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var result = await GetItemsToSerialize(request, user, parentItem).ConfigureAwait(false);

            var dtoOptions = GetDtoOptions(request);

            return(new ItemsResult
            {
                TotalRecordCount = result.Item1.TotalRecordCount,
                Items = _dtoService.GetBaseItemDtos(result.Item1.Items, dtoOptions, user).ToArray()
            });
        }
Esempio n. 3
0
        private QueryResult <BaseItemDto> GetResultItems(GetSuggestedItems request)
        {
            var user = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;

            var dtoOptions = GetDtoOptions(_authContext, request);
            var result     = GetItems(request, user, dtoOptions);

            var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user);

            return(new QueryResult <BaseItemDto>
            {
                TotalRecordCount = result.TotalRecordCount,
                Items = dtoList
            });
        }
Esempio n. 4
0
        private async Task <object> GetResult(IEnumerable <Audio> items, User user, BaseGetSimilarItems request)
        {
            var list = items.ToList();

            var result = new ItemsResult
            {
                TotalRecordCount = list.Count
            };

            var dtoOptions = GetDtoOptions(_authContext, request);

            result.Items = (await _dtoService.GetBaseItemDtos(list.Take(request.Limit ?? list.Count), dtoOptions, user).ConfigureAwait(false)).ToArray();

            return(ToOptimizedResult(result));
        }
Esempio n. 5
0
        internal static QueryResult <BaseItemDto> GetSimilarItemsResult(
            DtoOptions dtoOptions,
            IUserManager userManager,
            ILibraryManager libraryManager,
            IDtoService dtoService,
            Guid?userId,
            string id,
            string?excludeArtistIds,
            int?limit,
            Type[] includeTypes,
            Func <BaseItem, List <PersonInfo>, List <PersonInfo>, BaseItem, int> getSimilarityScore)
        {
            var user = userId.HasValue && !userId.Equals(Guid.Empty)
                ? userManager.GetUserById(userId.Value)
                : null;

            var item = string.IsNullOrEmpty(id) ?
                       (!userId.Equals(Guid.Empty) ? libraryManager.GetUserRootFolder() :
                        libraryManager.RootFolder) : libraryManager.GetItemById(id);

            var query = new InternalItemsQuery(user)
            {
                IncludeItemTypes = includeTypes.Select(i => i.Name).ToArray(),
                Recursive        = true,
                DtoOptions       = dtoOptions,
                ExcludeArtistIds = RequestHelpers.GetGuids(excludeArtistIds)
            };

            var inputItems = libraryManager.GetItemList(query);

            var items = GetSimilaritems(item, libraryManager, inputItems, getSimilarityScore)
                        .ToList();

            var returnItems = items;

            if (limit.HasValue)
            {
                returnItems = returnItems.Take(limit.Value).ToList();
            }

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

            return(new QueryResult <BaseItemDto>
            {
                Items = dtos,
                TotalRecordCount = items.Count
            });
        }
Esempio n. 6
0
        public ActionResult <QueryResult <BaseItemDto> > GetNextUp(
            [FromQuery] Guid?userId,
            [FromQuery] int?startIndex,
            [FromQuery] int?limit,
            [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
            [FromQuery] string?seriesId,
            [FromQuery] Guid?parentId,
            [FromQuery] bool?enableImages,
            [FromQuery] int?imageTypeLimit,
            [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
            [FromQuery] bool?enableUserData,
            [FromQuery] DateTime?nextUpDateCutoff,
            [FromQuery] bool enableTotalRecordCount = true,
            [FromQuery] bool disableFirstEpisode    = false,
            [FromQuery] bool rewatching             = false)
        {
            var options = new DtoOptions {
                Fields = fields
            }
            .AddClientFields(Request)
            .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);

            var result = _tvSeriesManager.GetNextUp(
                new NextUpQuery
            {
                Limit                  = limit,
                ParentId               = parentId,
                SeriesId               = seriesId,
                StartIndex             = startIndex,
                UserId                 = userId ?? Guid.Empty,
                EnableTotalRecordCount = enableTotalRecordCount,
                DisableFirstEpisode    = disableFirstEpisode,
                NextUpDateCutoff       = nextUpDateCutoff ?? DateTime.MinValue,
                Rewatching             = rewatching
            },
                options);

            var user = userId.HasValue && !userId.Equals(Guid.Empty)
                ? _userManager.GetUserById(userId.Value)
                : null;

            var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user);

            return(new QueryResult <BaseItemDto>(
                       startIndex,
                       result.TotalRecordCount,
                       returnItems));
        }
Esempio n. 7
0
        public async Task <object> Get(GetPlaylistItems request)
        {
            var playlist = (Playlist)_libraryManager.GetItemById(request.Id);
            var user     = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var items = playlist.GetManageableItems().ToArray();

            var count = items.Length;

            if (request.StartIndex.HasValue)
            {
                items = items.Skip(request.StartIndex.Value).ToArray();
            }

            if (request.Limit.HasValue)
            {
                items = items.Take(request.Limit.Value).ToArray();
            }

            var dtoOptions = GetDtoOptions(_authContext, request);

            var returnList = (await _dtoService.GetBaseItemDtos(items.Select(i => i.Item2), dtoOptions, user)
                              .ConfigureAwait(false));
            var dtos = returnList
                       .ToArray(returnList.Count);

            var index = 0;

            foreach (var item in dtos)
            {
                item.PlaylistItemId = items[index].Item1.Id;
                index++;
            }

            var result = new ItemsResult
            {
                Items            = dtos,
                TotalRecordCount = count
            };

            return(ToOptimizedResult(result));
        }
Esempio n. 8
0
        private QueryResult <BaseItemDto> GetResultItems(GetSuggestedItems request)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var dtoOptions = GetDtoOptions(_authContext, request);
            var result     = GetItems(request, user, dtoOptions);

            var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user);

            if (dtoList == null)
            {
                throw new InvalidOperationException("GetBaseItemDtos returned null");
            }

            return(new QueryResult <BaseItemDto>
            {
                TotalRecordCount = result.TotalRecordCount,
                Items = dtoList
            });
        }
Esempio n. 9
0
        private object GetResult(List <BaseItem> items, User user, BaseGetSimilarItems request, DtoOptions dtoOptions)
        {
            var list = items;

            var result = new QueryResult <BaseItemDto>
            {
                TotalRecordCount = list.Count
            };

            if (request.Limit.HasValue)
            {
                list = list.Take(request.Limit.Value).ToList();
            }

            var returnList = _dtoService.GetBaseItemDtos(list, dtoOptions, user);

            result.Items = returnList;

            return(ToOptimizedResult(result));
        }
Esempio n. 10
0
        public QueryResult <BaseItemDto> GetChannels(ChannelQuery query)
        {
            var user = query.UserId.Equals(Guid.Empty)
                ? null
                : _userManager.GetUserById(query.UserId);

            var internalResult = GetChannelsInternal(query);

            var dtoOptions = new DtoOptions();

            // TODO Fix The co-variant conversion (internalResult.Items) between Folder[] and BaseItem[], this can generate runtime issues.
            var returnItems = _dtoService.GetBaseItemDtos(internalResult.Items, dtoOptions, user);

            var result = new QueryResult <BaseItemDto>(
                query.StartIndex,
                internalResult.TotalRecordCount,
                returnItems);

            return(result);
        }
Esempio n. 11
0
        public ActionResult <IEnumerable <BaseItemDto> > GetLocalTrailers([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
        {
            var user = _userManager.GetUserById(userId);

            var item = itemId.Equals(Guid.Empty)
                ? _libraryManager.GetUserRootFolder()
                : _libraryManager.GetItemById(itemId);

            var dtoOptions = new DtoOptions().AddClientFields(Request);

            if (item is IHasTrailers hasTrailers)
            {
                var trailers = hasTrailers.LocalTrailers;
                return(Ok(_dtoService.GetBaseItemDtos(trailers, dtoOptions, user, item)));
            }

            return(Ok(item.GetExtras()
                      .Where(e => e.ExtraType == ExtraType.Trailer)
                      .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))));
        }
Esempio n. 12
0
        public object Get(GetPlaylistItems request)
        {
            var playlist = (Playlist)_libraryManager.GetItemById(request.Id);
            var user     = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;

            var items = playlist.GetManageableItems().ToArray();

            var count = items.Length;

            if (request.StartIndex.HasValue)
            {
                items = items.Skip(request.StartIndex.Value).ToArray();
            }

            if (request.Limit.HasValue)
            {
                items = items.Take(request.Limit.Value).ToArray();
            }

            var dtoOptions = GetDtoOptions(_authContext, request);

            var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user);

            var index = 0;

            foreach (var item in dtos)
            {
                item.PlaylistItemId = items[index].Item1.Id;
                index++;
            }

            var result = new QueryResult <BaseItemDto>
            {
                Items            = dtos,
                TotalRecordCount = count
            };

            return(ToOptimizedResult(result));
        }
Esempio n. 13
0
        public object Get(GetSyncDialogOptions request)
        {
            var result = new SyncDialogOptions();

            result.Targets = _syncManager.GetSyncTargets(request.UserId)
                             .ToList();

            if (request.Category.HasValue)
            {
                result.Options = SyncHelper.GetSyncOptions(request.Category.Value);
            }
            else
            {
                var dtoOptions = new DtoOptions
                {
                    Fields = new List <ItemFields>
                    {
                        ItemFields.SyncInfo
                    }
                };

                var auth = AuthorizationContext.GetAuthorizationInfo(Request);

                var authenticatedUser = _userManager.GetUserById(auth.UserId);

                var items = request.ItemIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(_libraryManager.GetItemById)
                            .Where(i => i != null);

                var dtos = _dtoService.GetBaseItemDtos(items, dtoOptions, authenticatedUser)
                           .ToList();

                result.Options = SyncHelper.GetSyncOptions(dtos);
            }

            return(ToOptimizedResult(result));
        }