public async Task <ActionResult <QueryResult <BaseItemDto> > > GetLatestChannelItems( [FromQuery] Guid?userId, [FromQuery] int?startIndex, [FromQuery] int?limit, [FromQuery] string?filters, [FromQuery] string?fields, [FromQuery] string?channelIds) { var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; var query = new InternalItemsQuery(user) { Limit = limit, StartIndex = startIndex, ChannelIds = (channelIds ?? string.Empty) .Split(',') .Where(i => !string.IsNullOrWhiteSpace(i)) .Select(i => new Guid(i)) .ToArray(), DtoOptions = new DtoOptions() .AddItemFields(fields) }; foreach (var filter in RequestHelpers.GetFilters(filters)) { switch (filter) { case ItemFilter.IsFolder: query.IsFolder = true; break; case ItemFilter.IsNotFolder: query.IsFolder = false; break; case ItemFilter.IsUnplayed: query.IsPlayed = false; break; case ItemFilter.IsPlayed: query.IsPlayed = true; break; case ItemFilter.IsFavorite: query.IsFavorite = true; break; case ItemFilter.IsResumable: query.IsResumable = true; break; case ItemFilter.Likes: query.IsLiked = true; break; case ItemFilter.Dislikes: query.IsLiked = false; break; case ItemFilter.IsFavoriteOrLikes: query.IsFavoriteOrLiked = true; break; } } return(await _channelManager.GetLatestChannelItems(query, CancellationToken.None).ConfigureAwait(false)); }
public ActionResult <QueryResult <BaseItemDto> > GetPersons( [FromQuery] double?minCommunityRating, [FromQuery] int?startIndex, [FromQuery] int?limit, [FromQuery] string?searchTerm, [FromQuery] string?parentId, [FromQuery] string?fields, [FromQuery] string?excludeItemTypes, [FromQuery] string?includeItemTypes, [FromQuery] string?filters, [FromQuery] bool?isFavorite, [FromQuery] string?mediaTypes, [FromQuery] string?genres, [FromQuery] string?genreIds, [FromQuery] string?officialRatings, [FromQuery] string?tags, [FromQuery] string?years, [FromQuery] bool?enableUserData, [FromQuery] int?imageTypeLimit, [FromQuery] string?enableImageTypes, [FromQuery] string?person, [FromQuery] string?personIds, [FromQuery] string?personTypes, [FromQuery] string?studios, [FromQuery] string?studioIds, [FromQuery] Guid?userId, [FromQuery] string?nameStartsWithOrGreater, [FromQuery] string?nameStartsWith, [FromQuery] string?nameLessThan, [FromQuery] bool?enableImages = true, [FromQuery] bool enableTotalRecordCount = true) { var dtoOptions = new DtoOptions() .AddItemFields(fields) .AddClientFields(Request) .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); User? user = null; BaseItem parentItem; if (userId.HasValue && !userId.Equals(Guid.Empty)) { user = _userManager.GetUserById(userId.Value); parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(parentId); } else { parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.RootFolder : _libraryManager.GetItemById(parentId); } var query = new InternalItemsQuery(user) { ExcludeItemTypes = RequestHelpers.Split(excludeItemTypes, ',', true), IncludeItemTypes = RequestHelpers.Split(includeItemTypes, ',', true), MediaTypes = RequestHelpers.Split(mediaTypes, ',', true), StartIndex = startIndex, Limit = limit, IsFavorite = isFavorite, NameLessThan = nameLessThan, NameStartsWith = nameStartsWith, NameStartsWithOrGreater = nameStartsWithOrGreater, Tags = RequestHelpers.Split(tags, '|', true), OfficialRatings = RequestHelpers.Split(officialRatings, '|', true), Genres = RequestHelpers.Split(genres, '|', true), GenreIds = RequestHelpers.GetGuids(genreIds), StudioIds = RequestHelpers.GetGuids(studioIds), Person = person, PersonIds = RequestHelpers.GetGuids(personIds), PersonTypes = RequestHelpers.Split(personTypes, ',', true), Years = RequestHelpers.Split(years, ',', true).Select(y => Convert.ToInt32(y, CultureInfo.InvariantCulture)).ToArray(), MinCommunityRating = minCommunityRating, DtoOptions = dtoOptions, SearchTerm = searchTerm, EnableTotalRecordCount = enableTotalRecordCount }; if (!string.IsNullOrWhiteSpace(parentId)) { if (parentItem is Folder) { query.AncestorIds = new[] { new Guid(parentId) }; } else { query.ItemIds = new[] { new Guid(parentId) }; } } // Studios if (!string.IsNullOrEmpty(studios)) { query.StudioIds = 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 RequestHelpers.GetFilters(filters)) { 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 = new QueryResult <(BaseItem, ItemCounts)>(); var dtos = result.Items.Select(i => { var(baseItem, counts) = i; var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user); if (!string.IsNullOrWhiteSpace(includeItemTypes)) { dto.ChildCount = counts.ItemCount; dto.ProgramCount = counts.ProgramCount; dto.SeriesCount = counts.SeriesCount; dto.EpisodeCount = counts.EpisodeCount; dto.MovieCount = counts.MovieCount; dto.TrailerCount = counts.TrailerCount; dto.AlbumCount = counts.AlbumCount; dto.SongCount = counts.SongCount; dto.ArtistCount = counts.ArtistCount; } return(dto); }); return(new QueryResult <BaseItemDto> { Items = dtos.ToArray(), TotalRecordCount = result.TotalRecordCount }); }
public async Task <ActionResult <QueryResult <BaseItemDto> > > GetChannelItems( [FromRoute] Guid channelId, [FromQuery] Guid?folderId, [FromQuery] Guid?userId, [FromQuery] int?startIndex, [FromQuery] int?limit, [FromQuery] string?sortOrder, [FromQuery] string?filters, [FromQuery] string?sortBy, [FromQuery] string?fields) { var user = userId.HasValue && !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId.Value) : null; var query = new InternalItemsQuery(user) { Limit = limit, StartIndex = startIndex, ChannelIds = new[] { channelId }, ParentId = folderId ?? Guid.Empty, OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder), DtoOptions = new DtoOptions() .AddItemFields(fields) }; foreach (var filter in RequestHelpers.GetFilters(filters)) { switch (filter) { case ItemFilter.IsFolder: query.IsFolder = true; break; case ItemFilter.IsNotFolder: query.IsFolder = false; break; case ItemFilter.IsUnplayed: query.IsPlayed = false; break; case ItemFilter.IsPlayed: query.IsPlayed = true; break; case ItemFilter.IsFavorite: query.IsFavorite = true; break; case ItemFilter.IsResumable: query.IsResumable = true; break; case ItemFilter.Likes: query.IsLiked = true; break; case ItemFilter.Dislikes: query.IsLiked = false; break; case ItemFilter.IsFavoriteOrLikes: query.IsFavoriteOrLiked = true; break; } } return(await _channelManager.GetChannelItems(query, CancellationToken.None).ConfigureAwait(false)); }