Esempio n. 1
0
        /// <summary>
        /// Gets the ancestors.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{BaseItemDto[]}.</returns>
        public List <BaseItemDto> GetAncestors(GetAncestors request)
        {
            var item = _dtoService.GetItemByDtoId(request.Id);

            var baseItemDtos = new List <BaseItemDto>();

            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields))
                         .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
                         .ToList();

            BaseItem parent = item.Parent;

            while (parent != null)
            {
                if (user != null)
                {
                    parent = TranslateParentItem(parent, user);
                }

                baseItemDtos.Add(_dtoService.GetBaseItemDto(parent, fields, user));

                if (parent is UserRootFolder)
                {
                    break;
                }

                parent = parent.Parent;
            }

            return(baseItemDtos.ToList());
        }
Esempio n. 2
0
        public Task <QueryResult <BaseItemDto> > GetChannels(ChannelQuery query, CancellationToken cancellationToken)
        {
            var user = string.IsNullOrWhiteSpace(query.UserId)
                ? null
                : _userManager.GetUserById(new Guid(query.UserId));

            var channels = _channelEntities.OrderBy(i => i.SortName).ToList();

            if (user != null)
            {
                channels = channels.Where(i => GetChannelProvider(i).IsEnabledFor(user) && i.IsVisible(user))
                           .ToList();
            }

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields))
                         .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
                         .ToList();

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

            var result = new QueryResult <BaseItemDto>
            {
                Items            = returnItems,
                TotalRecordCount = returnItems.Length
            };

            return(Task.FromResult(result));
        }
Esempio n. 3
0
        public ActionResult <BaseItemDto> GetGenre([FromRoute, Required] string genreName, [FromQuery] Guid?userId)
        {
            var dtoOptions = new DtoOptions()
                             .AddClientFields(Request);

            Genre item = new Genre();

            if (genreName.IndexOf(BaseItem.SlugChar, StringComparison.OrdinalIgnoreCase) != -1)
            {
                var result = GetItemFromSlugName <Genre>(_libraryManager, genreName, dtoOptions);

                if (result != null)
                {
                    item = result;
                }
            }
            else
            {
                item = _libraryManager.GetGenre(genreName);
            }

            if (userId.HasValue && !userId.Equals(Guid.Empty))
            {
                var user = _userManager.GetUserById(userId.Value);

                return(_dtoService.GetBaseItemDto(item, dtoOptions, user));
            }

            return(_dtoService.GetBaseItemDto(item, dtoOptions));
        }
Esempio n. 4
0
        public object Get(GetUpcomingEpisodes request)
        {
            var user = _userManager.GetUserById(request.UserId);

            var items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager, request.ParentId)
                        .OfType <Episode>();

            var itemsList = _libraryManager.Sort(items, user, new[] { "PremiereDate", "AirTime", "SortName" }, SortOrder.Ascending)
                            .Cast <Episode>()
                            .ToList();

            var unairedEpisodes = itemsList.Where(i => i.IsUnaired).ToList();

            var minPremiereDate  = DateTime.Now.Date.AddDays(-1).ToUniversalTime();
            var previousEpisodes = itemsList.Where(i => !i.IsUnaired && (i.PremiereDate ?? DateTime.MinValue) >= minPremiereDate).ToList();

            previousEpisodes.AddRange(unairedEpisodes);

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

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

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

            var result = new ItemsResult
            {
                TotalRecordCount = itemsList.Count,
                Items            = returnItems
            };

            return(ToOptimizedSerializedResultUsingCache(result));
        }
Esempio n. 5
0
        public object Get(GetMediaFolders request)
        {
            var items = _libraryManager.GetUserRootFolder().Children.OrderBy(i => i.SortName).ToList();

            if (request.IsHidden.HasValue)
            {
                var val = request.IsHidden.Value;

                items = items.Where(i => i.IsHidden == val).ToList();
            }

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields))
                         .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
                         .ToList();

            var result = new ItemsResult
            {
                TotalRecordCount = items.Count,

                Items = items.Select(i => _dtoService.GetBaseItemDto(i, fields)).ToArray()
            };

            return(ToOptimizedResult(result));
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the ancestors.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Task{BaseItemDto[]}.</returns>
        public async Task <BaseItemDto[]> GetAncestors(GetAncestors request)
        {
            var item = _dtoService.GetItemByDtoId(request.Id);

            var tasks = new List <Task <BaseItemDto> >();

            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields))
                         .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
                         .ToList();

            BaseItem parent = item.Parent;

            while (parent != null)
            {
                if (user != null)
                {
                    parent = TranslateParentItem(parent, user);
                }

                tasks.Add(_dtoService.GetBaseItemDto(parent, fields, user));

                if (parent is UserRootFolder)
                {
                    break;
                }

                parent = parent.Parent;
            }

            return(await Task.WhenAll(tasks).ConfigureAwait(false));
        }
Esempio n. 7
0
        private async Task <ItemsResult> GetSimilarItemsResult(BaseGetSimilarItemsFromItem request, Func <BaseItem, bool> includeInSearch, Func <BaseItem, BaseItem, int> getSimilarityScore)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (request.UserId.HasValue ? user.RootFolder :
                        _libraryManager.RootFolder) : _libraryManager.GetItemById(request.Id);

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

            var inputItems = user == null
                                 ? _libraryManager.RootFolder.GetRecursiveChildren().Where(i => i.Id != item.Id)
                                 : user.RootFolder.GetRecursiveChildren(user).Where(i => i.Id != item.Id);

            inputItems = inputItems.Where(includeInSearch);

            var list = inputItems.ToList();

            if (item is Movie && user != null && user.Configuration.IncludeTrailersInSuggestions)
            {
                var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
                {
                    ContentTypes = new[] { ChannelMediaContentType.MovieExtra },
                    ExtraTypes   = new[] { ExtraType.Trailer },
                    UserId       = user.Id.ToString("N")
                }, CancellationToken.None).ConfigureAwait(false);

                var newTrailers = trailerResult.Items;

                list.AddRange(newTrailers);

                list = list
                       .DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
                       .DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString(), StringComparer.OrdinalIgnoreCase)
                       .ToList();
            }

            var items = SimilarItemsHelper.GetSimilaritems(item, list, getSimilarityScore).ToList();

            IEnumerable <BaseItem> returnItems = items;

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

            var result = new ItemsResult
            {
                Items = returnItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(),

                TotalRecordCount = items.Count
            };

            return(result);
        }
Esempio n. 8
0
        private Task <BaseItemDto[]> GetAsync(GetSpecialFeatures request)
        {
            var user = _userManager.GetUserById(request.UserId);

            var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();

            var movie = item as Movie;

            // Get them from the db
            if (movie != null)
            {
                // Avoid implicitly captured closure
                var movie1 = movie;

                var tasks = movie.SpecialFeatureIds
                            .Select(_itemRepo.RetrieveItem)
                            .OrderBy(i => i.SortName)
                            .Select(i => _dtoService.GetBaseItemDto(i, fields, user, movie1));

                return(Task.WhenAll(tasks));
            }

            var series = item as Series;

            // Get them from the child tree
            if (series != null)
            {
                var tasks = series
                            .RecursiveChildren
                            .OfType <Episode>()
                            .Where(i => i.ParentIndexNumber.HasValue && i.ParentIndexNumber.Value == 0)
                            .OrderBy(i =>
                {
                    if (i.PremiereDate.HasValue)
                    {
                        return(i.PremiereDate.Value);
                    }

                    if (i.ProductionYear.HasValue)
                    {
                        return(new DateTime(i.ProductionYear.Value, 1, 1, 0, 0, 0, DateTimeKind.Utc));
                    }
                    return(DateTime.MinValue);
                })
                            .ThenBy(i => i.SortName)
                            .Select(i => _dtoService.GetBaseItemDto(i, fields, user));

                return(Task.WhenAll(tasks));
            }

            throw new ArgumentException("The item does not support special features");
        }
Esempio n. 9
0
        public ActionResult <ThemeMediaResult> GetThemeSongs(
            [FromRoute, Required] Guid itemId,
            [FromQuery] Guid?userId,
            [FromQuery] bool inheritFromParent = false)
        {
            var user = userId.HasValue && !userId.Equals(Guid.Empty)
                ? _userManager.GetUserById(userId.Value)
                : null;

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

            if (item == null)
            {
                return(NotFound("Item not found."));
            }

            IEnumerable <BaseItem> themeItems;

            while (true)
            {
                themeItems = item.GetThemeSongs();

                if (themeItems.Any() || !inheritFromParent)
                {
                    break;
                }

                var parent = item.GetParent();
                if (parent == null)
                {
                    break;
                }

                item = parent;
            }

            var dtoOptions = new DtoOptions().AddClientFields(Request);
            var items      = themeItems
                             .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))
                             .ToArray();

            return(new ThemeMediaResult
            {
                Items = items,
                TotalRecordCount = items.Length,
                OwnerId = item.Id
            });
        }
Esempio n. 10
0
        public ActionResult <BaseItemDto> GetArtistByName([FromRoute, Required] string name, [FromQuery] Guid?userId)
        {
            var dtoOptions = new DtoOptions().AddClientFields(Request);

            var item = _libraryManager.GetArtist(name, dtoOptions);

            if (userId.HasValue && !userId.Equals(Guid.Empty))
            {
                var user = _userManager.GetUserById(userId.Value);

                return(_dtoService.GetBaseItemDto(item, dtoOptions, user));
            }

            return(_dtoService.GetBaseItemDto(item, dtoOptions));
        }
Esempio n. 11
0
        public async Task <ActionResult <CollectionCreationResult> > CreateCollection(
            [FromQuery] string?name,
            [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] ids,
            [FromQuery] Guid?parentId,
            [FromQuery] bool isLocked = false)
        {
            var userId = (await _authContext.GetAuthorizationInfo(Request).ConfigureAwait(false)).UserId;

            var item = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions
            {
                IsLocked   = isLocked,
                Name       = name,
                ParentId   = parentId,
                ItemIdList = ids,
                UserIds    = new[] { userId }
            }).ConfigureAwait(false);

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

            var dto = _dtoService.GetBaseItemDto(item, dtoOptions);

            return(new CollectionCreationResult
            {
                Id = dto.Id
            });
        }
Esempio n. 12
0
        public async Task<object> Post(CreateCollection request)
        {
            var userId = _authContext.GetAuthorizationInfo(Request).UserId;

            var parentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);

            var item = await _collectionManager.CreateCollection(new CollectionCreationOptions
            {
                IsLocked = request.IsLocked,
                Name = request.Name,
                ParentId = parentId,
                ItemIdList = SplitValue(request.Ids, ','),
                UserIds = new string[] { userId }

            }).ConfigureAwait(false);

            var dtoOptions = GetDtoOptions(_authContext, request);

            var dto = _dtoService.GetBaseItemDto(item, dtoOptions);

            return ToOptimizedResult(new CollectionCreationResult
            {
                Id = dto.Id
            });
        }
Esempio n. 13
0
        /// <summary>
        /// Gets the similar items.
        /// </summary>
        /// <param name="userManager">The user manager.</param>
        /// <param name="itemRepository">The item repository.</param>
        /// <param name="libraryManager">The library manager.</param>
        /// <param name="userDataRepository">The user data repository.</param>
        /// <param name="dtoService">The dto service.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        /// <param name="includeInSearch">The include in search.</param>
        /// <param name="getSimilarityScore">The get similarity score.</param>
        /// <returns>ItemsResult.</returns>
        internal static ItemsResult GetSimilarItemsResult(IUserManager userManager, IItemRepository itemRepository, ILibraryManager libraryManager, IUserDataManager userDataRepository, IDtoService dtoService, ILogger logger, BaseGetSimilarItemsFromItem request, Func <BaseItem, bool> includeInSearch, Func <BaseItem, BaseItem, int> getSimilarityScore)
        {
            var user = request.UserId.HasValue ? userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id) ?
                       (request.UserId.HasValue ? user.RootFolder :
                        (Folder)libraryManager.RootFolder) : dtoService.GetItemByDtoId(request.Id, request.UserId);

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

            var inputItems = user == null
                                 ? libraryManager.RootFolder.GetRecursiveChildren(i => i.Id != item.Id)
                                 : user.RootFolder.GetRecursiveChildren(user, i => i.Id != item.Id);

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

            IEnumerable <BaseItem> returnItems = items;

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

            var result = new ItemsResult
            {
                Items = returnItems.Select(i => dtoService.GetBaseItemDto(i, fields, user)).ToArray(),

                TotalRecordCount = items.Count
            };

            return(result);
        }
Esempio n. 14
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetAdditionalParts request)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (request.UserId.HasValue
                                  ? user.RootFolder
                                  : _libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields))
                         .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
                         .ToList();

            var video = (Video)item;

            var items = video.GetAdditionalParts()
                        .Select(i => _dtoService.GetBaseItemDto(i, fields, user, video))
                        .ToArray();

            var result = new ItemsResult
            {
                Items            = items,
                TotalRecordCount = items.Length
            };

            return(ToOptimizedSerializedResultUsingCache(result));
        }
Esempio n. 15
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetAdditionalParts request)
        {
            var user = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (!request.UserId.Equals(Guid.Empty)
                                  ? _libraryManager.GetUserRootFolder()
                                  : _libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            var dtoOptions = GetDtoOptions(_authContext, request);

            BaseItemDto[] items;
            if (item is Video video)
            {
                items = video.GetAdditionalParts()
                        .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video))
                        .ToArray();
            }
            else
            {
                items = Array.Empty <BaseItemDto>();
            }

            var result = new QueryResult <BaseItemDto>
            {
                Items            = items,
                TotalRecordCount = items.Length
            };

            return(ToOptimizedResult(result));
        }
Esempio n. 16
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 dtos = request.ItemIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                           .Select(_libraryManager.GetItemById)
                           .Where(i => i != null)
                           .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions))
                           .ToList();

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

            return(ToOptimizedResult(result));
        }
Esempio n. 17
0
        public ActionResult <QueryResult <BaseItemDto> > GetAdditionalPart([FromRoute, Required] Guid itemId, [FromQuery] Guid?userId)
        {
            var user = userId.HasValue && !userId.Equals(Guid.Empty)
                ? _userManager.GetUserById(userId.Value)
                : null;

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

            var dtoOptions = new DtoOptions();

            dtoOptions = dtoOptions.AddClientFields(Request);

            BaseItemDto[] items;
            if (item is Video video)
            {
                items = video.GetAdditionalParts()
                        .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video))
                        .ToArray();
            }
            else
            {
                items = Array.Empty <BaseItemDto>();
            }

            var result = new QueryResult <BaseItemDto>(items);

            return(result);
        }
Esempio n. 18
0
        public async Task <object> Get(GetUserViews request)
        {
            var query = new UserViewQuery
            {
                UserId = request.UserId
            };

            if (request.IncludeExternalContent.HasValue)
            {
                query.IncludeExternalContent = request.IncludeExternalContent.Value;
            }

            var folders = await _userViewManager.GetUserViews(query, CancellationToken.None).ConfigureAwait(false);

            var dtoOptions = GetDtoOptions(request);

            var user = _userManager.GetUserById(request.UserId);

            var dtos = folders.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user))
                       .ToArray();

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

            return(ToOptimizedResult(result));
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetAdditionalParts request)
        {
            var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (!string.IsNullOrWhiteSpace(request.UserId)
                                  ? user.RootFolder
                                  : _libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            var dtoOptions = GetDtoOptions(_authContext, request);

            var video = item as Video;

            BaseItemDto[] items;
            if (video != null)
            {
                items = video.GetAdditionalParts()
                        .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video))
                        .ToArray();
            }
            else
            {
                items = new BaseItemDto[] { };
            }

            var result = new ItemsResult
            {
                Items            = items,
                TotalRecordCount = items.Length
            };

            return(ToOptimizedSerializedResultUsingCache(result));
        }
        public async Task <object> Post(CreateCollection request)
        {
            var userId = AuthorizationContext.GetAuthorizationInfo(Request).UserId;

            var parentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);

            var item = await _collectionManager.CreateCollection(new CollectionCreationOptions
            {
                IsLocked   = request.IsLocked,
                Name       = request.Name,
                ParentId   = parentId,
                ItemIdList = (request.Ids ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(i => new Guid(i)).ToList(),
                UserIds    = new List <Guid> {
                    new Guid(userId)
                }
            }).ConfigureAwait(false);

            var dtoOptions = GetDtoOptions(request);

            var dto = _dtoService.GetBaseItemDto(item, dtoOptions);

            return(ToOptimizedResult(new CollectionCreationResult
            {
                Id = dto.Id
            }));
        }
Esempio n. 21
0
        public async Task <ActionResult <CollectionCreationResult> > CreateCollection(
            [FromQuery] string?name,
            [FromQuery] string?ids,
            [FromQuery] Guid?parentId,
            [FromQuery] bool isLocked = false)
        {
            var userId = _authContext.GetAuthorizationInfo(Request).UserId;

            var item = await _collectionManager.CreateCollectionAsync(new CollectionCreationOptions
            {
                IsLocked   = isLocked,
                Name       = name,
                ParentId   = parentId,
                ItemIdList = RequestHelpers.Split(ids, ',', true),
                UserIds    = new[] { userId }
            }).ConfigureAwait(false);

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

            var dto = _dtoService.GetBaseItemDto(item, dtoOptions);

            return(new CollectionCreationResult
            {
                Id = dto.Id
            });
        }
Esempio n. 22
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetAdditionalParts request)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var item = string.IsNullOrEmpty(request.Id)
                           ? (request.UserId.HasValue
                                  ? user.RootFolder
                                  : _libraryManager.RootFolder)
                           : _libraryManager.GetItemById(request.Id);

            var dtoOptions = GetDtoOptions(request);

            var video = (Video)item;

            var items = video.GetAdditionalParts()
                        .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video))
                        .ToArray();

            var result = new ItemsResult
            {
                Items            = items,
                TotalRecordCount = items.Length
            };

            return(ToOptimizedSerializedResultUsingCache(result));
        }
Esempio n. 23
0
        public async Task <object> Get(Getrailers request)
        {
            var user   = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;
            var result = await GetAllTrailers(user).ConfigureAwait(false);

            IEnumerable <BaseItem> items = result.Items;

            // Apply filters
            // Run them starting with the ones that are likely to reduce the list the most
            foreach (var filter in request.GetFilters().OrderByDescending(f => (int)f))
            {
                items = ItemsService.ApplyFilter(items, filter, user, _userDataRepository);
            }

            items = _libraryManager.Sort(items, user, request.GetOrderBy(), request.SortOrder ?? SortOrder.Ascending);

            var itemsArray = items.ToList();

            var pagedItems = ApplyPaging(request, itemsArray);

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

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

            return(new ItemsResult
            {
                TotalRecordCount = itemsArray.Count,
                Items = returnItems
            });
        }
Esempio n. 24
0
        public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, LiveTvChannel channel)
        {
            var dto = new TimerInfoDto
            {
                Id                    = GetInternalTimerId(service.Name, info.Id).ToString("N"),
                Overview              = info.Overview,
                EndDate               = info.EndDate,
                Name                  = info.Name,
                StartDate             = info.StartDate,
                ExternalId            = info.Id,
                ChannelId             = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
                Status                = info.Status,
                SeriesTimerId         = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
                PrePaddingSeconds     = info.PrePaddingSeconds,
                PostPaddingSeconds    = info.PostPaddingSeconds,
                IsPostPaddingRequired = info.IsPostPaddingRequired,
                IsPrePaddingRequired  = info.IsPrePaddingRequired,
                ExternalChannelId     = info.ChannelId,
                ExternalSeriesTimerId = info.SeriesTimerId,
                ServiceName           = service.Name,
                ExternalProgramId     = info.ProgramId,
                Priority              = info.Priority,
                RunTimeTicks          = (info.EndDate - info.StartDate).Ticks,
                ServerId              = _appHost.SystemId
            };

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
            }

            if (program != null)
            {
                dto.ProgramInfo = _dtoService.GetBaseItemDto(program, new DtoOptions());

                dto.ProgramInfo.TimerId       = dto.Id;
                dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
            }

            if (channel != null)
            {
                dto.ChannelName = channel.Name;
            }

            return(dto);
        }
Esempio n. 25
0
        public object Get(GetUserViews request)
        {
            var user = _userManager.GetUserById(new Guid(request.UserId));

            // Get everything
            var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();

            var query = new UserViewQuery
            {
                UserId = request.UserId
            };

            if (request.IncludeExternalContent.HasValue)
            {
                query.IncludeExternalContent = request.IncludeExternalContent.Value;
            }

            var folders = _userViewManager.GetUserViews(query, CancellationToken.None).Result;

            var dtos = folders.OrderBy(i => i.SortName)
                       .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                       .ToArray();

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

            return(ToOptimizedResult(result));
        }
Esempio n. 26
0
        public object Post(CreatePlaylist request)
        {
            var task = _playlistManager.CreatePlaylist(new PlaylistCreationOptions
            {
                Name       = request.Name,
                ItemIdList = (request.Ids ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList(),
                UserId     = request.UserId
            });

            var item = task.Result;

            var dto = _dtoService.GetBaseItemDto(item, new List <ItemFields>());

            return(ToOptimizedResult(new PlaylistCreationResult
            {
                Id = dto.Id
            }));
        }
Esempio n. 27
0
        public ActionResult <BaseItemDto> GetYear([FromRoute, Required] int year, [FromQuery] Guid?userId)
        {
            var item = _libraryManager.GetYear(year);

            if (item == null)
            {
                return(NotFound());
            }

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

            if (userId.HasValue && !userId.Equals(Guid.Empty))
            {
                var user = _userManager.GetUserById(userId.Value);
                return(_dtoService.GetBaseItemDto(item, dtoOptions, user));
            }

            return(_dtoService.GetBaseItemDto(item, dtoOptions));
        }
Esempio n. 28
0
        public object Get(GetChannel request)
        {
            var user = string.IsNullOrWhiteSpace(request.UserId) ? null : _userManager.GetUserById(request.UserId);

            var item = _libraryManager.GetItemById(request.Id);

            var dtoOptions = GetDtoOptions(request);

            var result = _dtoService.GetBaseItemDto(item, dtoOptions, user);

            return(ToOptimizedSerializedResultUsingCache(result));
        }
Esempio n. 29
0
        public object Get(GetMediaFolders request)
        {
            var items = _libraryManager.GetUserRootFolder().Children.OrderBy(i => i.SortName).ToList();

            if (request.IsHidden.HasValue)
            {
                var val = request.IsHidden.Value;

                items = items.Where(i => i.IsHidden == val).ToList();
            }

            var dtoOptions = new DtoOptions();

            var result = new ItemsResult
            {
                TotalRecordCount = items.Count,

                Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions)).ToArray()
            };

            return(ToOptimizedResult(result));
        }
Esempio n. 30
0
        public object Get(GetMediaFolders request)
        {
            var items = _libraryManager.GetUserRootFolder().Children.Concat(_libraryManager.RootFolder.VirtualChildren).OrderBy(i => i.SortName).ToList();

            if (request.IsHidden.HasValue)
            {
                var val = request.IsHidden.Value;

                items = items.Where(i => i.IsHidden == val).ToList();
            }

            var dtoOptions = GetDtoOptions(_authContext, request);

            var result = new QueryResult <BaseItemDto>
            {
                TotalRecordCount = items.Count,

                Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions)).ToArray()
            };

            return(result);
        }