2020-11-18 14:23:45 +01:00
using System ;
2020-09-06 01:11:44 +02:00
using System.ComponentModel.DataAnnotations ;
2020-07-03 18:39:50 +02:00
using System.Globalization ;
using System.Linq ;
using Jellyfin.Api.Constants ;
using Jellyfin.Api.Extensions ;
using Jellyfin.Api.Helpers ;
2020-10-14 21:03:36 +02:00
using Jellyfin.Api.ModelBinders ;
2020-07-03 18:39:50 +02:00
using Jellyfin.Data.Enums ;
using MediaBrowser.Controller.Dto ;
using MediaBrowser.Controller.Entities ;
2020-08-29 19:30:09 +02:00
using MediaBrowser.Controller.Entities.Audio ;
2020-07-03 18:39:50 +02:00
using MediaBrowser.Controller.Library ;
using MediaBrowser.Model.Dto ;
using MediaBrowser.Model.Entities ;
using MediaBrowser.Model.Globalization ;
using MediaBrowser.Model.Querying ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Logging ;
namespace Jellyfin.Api.Controllers
{
/// <summary>
/// The items controller.
/// </summary>
2020-08-04 20:48:53 +02:00
[Route("")]
2020-07-03 18:39:50 +02:00
[Authorize(Policy = Policies.DefaultAuthorization)]
public class ItemsController : BaseJellyfinApiController
{
private readonly IUserManager _userManager ;
private readonly ILibraryManager _libraryManager ;
private readonly ILocalizationManager _localization ;
private readonly IDtoService _dtoService ;
2020-08-03 21:16:29 +02:00
private readonly ILogger < ItemsController > _logger ;
2020-07-03 18:39:50 +02:00
/// <summary>
/// Initializes a new instance of the <see cref="ItemsController"/> class.
/// </summary>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
public ItemsController (
IUserManager userManager ,
ILibraryManager libraryManager ,
ILocalizationManager localization ,
IDtoService dtoService ,
ILogger < ItemsController > logger )
{
_userManager = userManager ;
_libraryManager = libraryManager ;
_localization = localization ;
_dtoService = dtoService ;
_logger = logger ;
}
/// <summary>
/// Gets items based on a query.
/// </summary>
2020-07-05 11:10:09 +02:00
/// <param name="userId">The user id supplied as query parameter.</param>
2020-07-03 18:39:50 +02:00
/// <param name="maxOfficialRating">Optional filter by maximum official rating (PG, PG-13, TV-MA, etc).</param>
/// <param name="hasThemeSong">Optional filter by items with theme songs.</param>
/// <param name="hasThemeVideo">Optional filter by items with theme videos.</param>
/// <param name="hasSubtitles">Optional filter by items with subtitles.</param>
/// <param name="hasSpecialFeature">Optional filter by items with special features.</param>
/// <param name="hasTrailer">Optional filter by items with trailers.</param>
/// <param name="adjacentTo">Optional. Return items that are siblings of a supplied item.</param>
/// <param name="parentIndexNumber">Optional filter by parent index number.</param>
/// <param name="hasParentalRating">Optional filter by items that have or do not have a parental rating.</param>
/// <param name="isHd">Optional filter by items that are HD or not.</param>
/// <param name="is4K">Optional filter by items that are 4K or not.</param>
2020-11-18 14:23:45 +01:00
/// <param name="locationTypes">Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimited.</param>
/// <param name="excludeLocationTypes">Optional. If specified, results will be filtered based on the LocationType. This allows multiple, comma delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="isMissing">Optional filter by items that are missing episodes or not.</param>
/// <param name="isUnaired">Optional filter by items that are unaired episodes or not.</param>
/// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
/// <param name="minCriticRating">Optional filter by minimum critic rating.</param>
/// <param name="minPremiereDate">Optional. The minimum premiere date. Format = ISO.</param>
/// <param name="minDateLastSaved">Optional. The minimum last saved date. Format = ISO.</param>
/// <param name="minDateLastSavedForUser">Optional. The minimum last saved date for the current user. Format = ISO.</param>
/// <param name="maxPremiereDate">Optional. The maximum premiere date. Format = ISO.</param>
/// <param name="hasOverview">Optional filter by items that have an overview or not.</param>
/// <param name="hasImdbId">Optional filter by items that have an imdb id or not.</param>
/// <param name="hasTmdbId">Optional filter by items that have a tmdb id or not.</param>
/// <param name="hasTvdbId">Optional filter by items that have a tvdb id or not.</param>
2020-11-18 14:23:45 +01:00
/// <param name="excludeItemIds">Optional. If specified, results will be filtered by excluding item ids. This allows multiple, comma delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
/// <param name="limit">Optional. The maximum number of records to return.</param>
/// <param name="recursive">When searching within folders, this determines whether or not the search will be recursive. true/false.</param>
/// <param name="searchTerm">Optional. Filter based on a search term.</param>
/// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
/// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
2020-11-18 14:23:45 +01:00
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
/// <param name="excludeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.</param>
/// <param name="includeItemTypes">Optional. If specified, results will be filtered based on the item type. This allows multiple, comma delimited.</param>
/// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimited. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
2020-07-03 18:39:50 +02:00
/// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
/// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
/// <param name="imageTypes">Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.</param>
2020-11-18 14:23:45 +01:00
/// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
2020-07-03 18:39:50 +02:00
/// <param name="isPlayed">Optional filter by items that are played, or not.</param>
2020-11-18 14:23:45 +01:00
/// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimited.</param>
/// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimited.</param>
/// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimited.</param>
/// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="enableUserData">Optional, include user data.</param>
/// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
/// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
/// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person id.</param>
/// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.</param>
2020-11-18 14:23:45 +01:00
/// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimited.</param>
/// <param name="artists">Optional. If specified, results will be filtered based on artists. This allows multiple, pipe delimited.</param>
/// <param name="excludeArtistIds">Optional. If specified, results will be filtered based on artist id. This allows multiple, pipe delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="artistIds">Optional. If specified, results will be filtered to include only those containing the specified artist id.</param>
/// <param name="albumArtistIds">Optional. If specified, results will be filtered to include only those containing the specified album artist id.</param>
/// <param name="contributingArtistIds">Optional. If specified, results will be filtered to include only those containing the specified contributing artist id.</param>
2020-11-18 14:23:45 +01:00
/// <param name="albums">Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimited.</param>
/// <param name="albumIds">Optional. If specified, results will be filtered based on album id. This allows multiple, pipe delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="ids">Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.</param>
2020-11-18 14:23:45 +01:00
/// <param name="videoTypes">Optional filter by VideoType (videofile, dvd, bluray, iso). Allows multiple, comma delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="minOfficialRating">Optional filter by minimum official rating (PG, PG-13, TV-MA, etc).</param>
/// <param name="isLocked">Optional filter by items that are locked.</param>
/// <param name="isPlaceHolder">Optional filter by items that are placeholders.</param>
/// <param name="hasOfficialRating">Optional filter by items that have official ratings.</param>
/// <param name="collapseBoxSetItems">Whether or not to hide items behind their boxsets.</param>
/// <param name="minWidth">Optional. Filter by the minimum width of the item.</param>
/// <param name="minHeight">Optional. Filter by the minimum height of the item.</param>
/// <param name="maxWidth">Optional. Filter by the maximum width of the item.</param>
/// <param name="maxHeight">Optional. Filter by the maximum height of the item.</param>
/// <param name="is3D">Optional filter by items that are 3D, or not.</param>
2020-11-18 14:23:45 +01:00
/// <param name="seriesStatus">Optional filter by Series Status. Allows multiple, comma delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a given input string.</param>
/// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</param>
/// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</param>
2020-11-18 14:23:45 +01:00
/// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimited.</param>
/// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="enableTotalRecordCount">Optional. Enable the total record count.</param>
/// <param name="enableImages">Optional, include image information in output.</param>
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the items.</returns>
2020-08-04 20:48:53 +02:00
[HttpGet("Items")]
2020-07-03 18:39:50 +02:00
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult < QueryResult < BaseItemDto > > GetItems (
2020-07-07 17:10:51 +02:00
[FromQuery] Guid ? userId ,
2020-07-03 18:39:50 +02:00
[FromQuery] string? maxOfficialRating ,
[FromQuery] bool? hasThemeSong ,
[FromQuery] bool? hasThemeVideo ,
[FromQuery] bool? hasSubtitles ,
[FromQuery] bool? hasSpecialFeature ,
[FromQuery] bool? hasTrailer ,
[FromQuery] string? adjacentTo ,
[FromQuery] int? parentIndexNumber ,
[FromQuery] bool? hasParentalRating ,
[FromQuery] bool? isHd ,
[FromQuery] bool? is4K ,
2020-11-17 04:45:09 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] LocationType [ ] locationTypes ,
2020-10-14 21:03:36 +02:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] LocationType [ ] excludeLocationTypes ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool? isMissing ,
[FromQuery] bool? isUnaired ,
[FromQuery] double? minCommunityRating ,
[FromQuery] double? minCriticRating ,
[FromQuery] DateTime ? minPremiereDate ,
[FromQuery] DateTime ? minDateLastSaved ,
[FromQuery] DateTime ? minDateLastSavedForUser ,
[FromQuery] DateTime ? maxPremiereDate ,
[FromQuery] bool? hasOverview ,
[FromQuery] bool? hasImdbId ,
[FromQuery] bool? hasTmdbId ,
[FromQuery] bool? hasTvdbId ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] excludeItemIds ,
2020-07-03 18:39:50 +02:00
[FromQuery] int? startIndex ,
[FromQuery] int? limit ,
[FromQuery] bool? recursive ,
[FromQuery] string? searchTerm ,
2021-01-24 01:32:13 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] SortOrder [ ] sortOrder ,
2020-12-01 19:07:41 +01:00
[FromQuery] Guid ? parentId ,
2020-11-09 22:59:04 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields [ ] fields ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] excludeItemTypes ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] includeItemTypes ,
2020-10-14 21:03:36 +02:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter [ ] filters ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool? isFavorite ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] mediaTypes ,
2020-11-09 22:53:23 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType [ ] imageTypes ,
2021-01-24 01:32:13 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] sortBy ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool? isPlayed ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] genres ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] officialRatings ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] tags ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] int [ ] years ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool? enableUserData ,
[FromQuery] int? imageTypeLimit ,
2020-11-09 22:53:23 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType [ ] enableImageTypes ,
2020-07-03 18:39:50 +02:00
[FromQuery] string? person ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] personIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] personTypes ,
2020-11-17 04:37:43 +01:00
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] studios ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] artists ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] excludeArtistIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] artistIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] albumArtistIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] contributingArtistIds ,
2020-11-17 04:37:43 +01:00
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] albums ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] albumIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] ids ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] VideoType [ ] videoTypes ,
2020-07-03 18:39:50 +02:00
[FromQuery] string? minOfficialRating ,
[FromQuery] bool? isLocked ,
[FromQuery] bool? isPlaceHolder ,
[FromQuery] bool? hasOfficialRating ,
[FromQuery] bool? collapseBoxSetItems ,
[FromQuery] int? minWidth ,
[FromQuery] int? minHeight ,
[FromQuery] int? maxWidth ,
[FromQuery] int? maxHeight ,
[FromQuery] bool? is3D ,
2020-11-17 04:37:43 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] SeriesStatus [ ] seriesStatus ,
2020-07-03 18:39:50 +02:00
[FromQuery] string? nameStartsWithOrGreater ,
[FromQuery] string? nameStartsWith ,
[FromQuery] string? nameLessThan ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] studioIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] genreIds ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool enableTotalRecordCount = true ,
[FromQuery] bool? enableImages = true )
{
2020-07-07 17:10:51 +02:00
var user = userId . HasValue & & ! userId . Equals ( Guid . Empty )
? _userManager . GetUserById ( userId . Value )
: null ;
2020-10-29 18:36:45 +01:00
var dtoOptions = new DtoOptions { Fields = fields }
2020-07-03 18:39:50 +02:00
. AddClientFields ( Request )
. AddAdditionalDtoOptions ( enableImages , enableUserData , imageTypeLimit , enableImageTypes ) ;
2020-11-17 04:29:46 +01:00
if ( includeItemTypes . Length = = 1
& & ( includeItemTypes [ 0 ] . Equals ( "Playlist" , StringComparison . OrdinalIgnoreCase )
| | includeItemTypes [ 0 ] . Equals ( "BoxSet" , StringComparison . OrdinalIgnoreCase ) ) )
2020-07-03 18:39:50 +02:00
{
parentId = null ;
}
2020-12-02 00:16:17 +01:00
var item = _libraryManager . GetParentItem ( parentId , userId ) ;
2020-07-03 18:39:50 +02:00
QueryResult < BaseItem > result ;
if ( ! ( item is Folder folder ) )
{
folder = _libraryManager . GetUserRootFolder ( ) ;
}
if ( folder is IHasCollectionType hasCollectionType
& & string . Equals ( hasCollectionType . CollectionType , CollectionType . Playlists , StringComparison . OrdinalIgnoreCase ) )
{
recursive = true ;
2020-11-17 04:29:46 +01:00
includeItemTypes = new [ ] { "Playlist" } ;
2020-07-03 18:39:50 +02:00
}
2020-12-13 16:15:26 +01:00
var enabledChannels = user ! . GetPreferenceValues < Guid > ( PreferenceKind . EnabledChannels ) ;
2020-12-11 23:00:43 +01:00
2020-12-13 16:15:26 +01:00
bool isInEnabledFolder = Array . IndexOf ( user . GetPreferenceValues < Guid > ( PreferenceKind . EnabledFolders ) , item . Id ) ! = - 1
2020-07-03 18:39:50 +02:00
// Assume all folders inside an EnabledChannel are enabled
2020-12-11 23:00:43 +01:00
| | Array . IndexOf ( enabledChannels , item . Id ) ! = - 1
2020-08-27 16:12:32 +02:00
// Assume all items inside an EnabledChannel are enabled
2020-12-11 23:00:43 +01:00
| | Array . IndexOf ( enabledChannels , item . ChannelId ) ! = - 1 ;
2020-07-03 18:39:50 +02:00
var collectionFolders = _libraryManager . GetCollectionFolders ( item ) ;
foreach ( var collectionFolder in collectionFolders )
{
2020-12-13 16:15:26 +01:00
if ( user . GetPreferenceValues < Guid > ( PreferenceKind . EnabledFolders ) . Contains ( collectionFolder . Id ) )
2020-07-03 18:39:50 +02:00
{
isInEnabledFolder = true ;
}
}
if ( ! ( item is UserRootFolder )
& & ! isInEnabledFolder
& & ! user . HasPermission ( PermissionKind . EnableAllFolders )
& & ! user . HasPermission ( PermissionKind . EnableAllChannels ) )
{
_logger . LogWarning ( "{UserName} is not permitted to access Library {ItemName}." , user . Username , item . Name ) ;
return Unauthorized ( $"{user.Username} is not permitted to access Library {item.Name}." ) ;
}
2020-11-17 04:29:46 +01:00
if ( ( recursive . HasValue & & recursive . Value ) | | ids . Length ! = 0 | | ! ( item is UserRootFolder ) )
2020-07-03 18:39:50 +02:00
{
var query = new InternalItemsQuery ( user ! )
{
IsPlayed = isPlayed ,
2020-11-17 04:29:46 +01:00
MediaTypes = mediaTypes ,
IncludeItemTypes = includeItemTypes ,
ExcludeItemTypes = excludeItemTypes ,
2020-07-04 19:05:42 +02:00
Recursive = recursive ? ? false ,
2020-07-03 18:39:50 +02:00
OrderBy = RequestHelpers . GetOrderBy ( sortBy , sortOrder ) ,
IsFavorite = isFavorite ,
Limit = limit ,
StartIndex = startIndex ,
IsMissing = isMissing ,
IsUnaired = isUnaired ,
CollapseBoxSetItems = collapseBoxSetItems ,
NameLessThan = nameLessThan ,
NameStartsWith = nameStartsWith ,
NameStartsWithOrGreater = nameStartsWithOrGreater ,
HasImdbId = hasImdbId ,
IsPlaceHolder = isPlaceHolder ,
IsLocked = isLocked ,
MinWidth = minWidth ,
MinHeight = minHeight ,
MaxWidth = maxWidth ,
MaxHeight = maxHeight ,
Is3D = is3D ,
HasTvdbId = hasTvdbId ,
HasTmdbId = hasTmdbId ,
HasOverview = hasOverview ,
HasOfficialRating = hasOfficialRating ,
HasParentalRating = hasParentalRating ,
HasSpecialFeature = hasSpecialFeature ,
HasSubtitles = hasSubtitles ,
HasThemeSong = hasThemeSong ,
HasThemeVideo = hasThemeVideo ,
HasTrailer = hasTrailer ,
IsHD = isHd ,
Is4K = is4K ,
2020-11-17 04:29:46 +01:00
Tags = tags ,
OfficialRatings = officialRatings ,
Genres = genres ,
ArtistIds = artistIds ,
AlbumArtistIds = albumArtistIds ,
ContributingArtistIds = contributingArtistIds ,
GenreIds = genreIds ,
StudioIds = studioIds ,
2020-07-03 18:39:50 +02:00
Person = person ,
2020-11-17 04:29:46 +01:00
PersonIds = personIds ,
PersonTypes = personTypes ,
Years = years ,
2020-10-10 01:52:39 +02:00
ImageTypes = imageTypes ,
2020-11-17 04:29:46 +01:00
VideoTypes = videoTypes ,
2020-07-03 18:39:50 +02:00
AdjacentTo = adjacentTo ,
2020-11-17 04:29:46 +01:00
ItemIds = ids ,
2020-07-03 18:39:50 +02:00
MinCommunityRating = minCommunityRating ,
MinCriticRating = minCriticRating ,
2020-12-01 19:07:41 +01:00
ParentId = parentId ? ? Guid . Empty ,
2020-07-03 18:39:50 +02:00
ParentIndexNumber = parentIndexNumber ,
EnableTotalRecordCount = enableTotalRecordCount ,
2020-11-17 04:29:46 +01:00
ExcludeItemIds = excludeItemIds ,
2020-07-03 18:39:50 +02:00
DtoOptions = dtoOptions ,
SearchTerm = searchTerm ,
2020-07-04 19:05:42 +02:00
MinDateLastSaved = minDateLastSaved ? . ToUniversalTime ( ) ,
MinDateLastSavedForUser = minDateLastSavedForUser ? . ToUniversalTime ( ) ,
MinPremiereDate = minPremiereDate ? . ToUniversalTime ( ) ,
MaxPremiereDate = maxPremiereDate ? . ToUniversalTime ( ) ,
2020-07-03 18:39:50 +02:00
} ;
2020-11-17 04:29:46 +01:00
if ( ids . Length ! = 0 | | ! string . IsNullOrWhiteSpace ( searchTerm ) )
2020-07-03 18:39:50 +02:00
{
query . CollapseBoxSetItems = false ;
}
2020-10-10 01:41:17 +02:00
foreach ( var filter in filters )
2020-07-03 18:39:50 +02:00
{
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 ;
}
}
// Filter by Series Status
2020-11-17 04:45:09 +01:00
if ( seriesStatus . Length ! = 0 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 04:37:43 +01:00
query . SeriesStatuses = seriesStatus ;
2020-07-03 18:39:50 +02:00
}
// ExcludeLocationTypes
2020-10-10 01:46:39 +02:00
if ( excludeLocationTypes . Any ( t = > t = = LocationType . Virtual ) )
2020-07-03 18:39:50 +02:00
{
2020-10-10 01:46:39 +02:00
query . IsVirtualItem = false ;
2020-07-03 18:39:50 +02:00
}
2020-11-17 17:38:50 +01:00
if ( locationTypes . Length > 0 & & locationTypes . Length < 4 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 17:38:50 +01:00
query . IsVirtualItem = locationTypes . Contains ( LocationType . Virtual ) ;
2020-07-03 18:39:50 +02:00
}
// Min official rating
if ( ! string . IsNullOrWhiteSpace ( minOfficialRating ) )
{
query . MinParentalRating = _localization . GetRatingLevel ( minOfficialRating ) ;
}
// Max official rating
if ( ! string . IsNullOrWhiteSpace ( maxOfficialRating ) )
{
query . MaxParentalRating = _localization . GetRatingLevel ( maxOfficialRating ) ;
}
// Artists
2020-11-17 04:37:43 +01:00
if ( artists . Length ! = 0 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 04:37:43 +01:00
query . ArtistIds = artists . Select ( i = >
2020-07-03 18:39:50 +02:00
{
try
{
return _libraryManager . GetArtist ( i , new DtoOptions ( false ) ) ;
}
catch
{
return null ;
}
} ) . Where ( i = > i ! = null ) . Select ( i = > i ! . Id ) . ToArray ( ) ;
}
// ExcludeArtistIds
2020-11-17 04:29:46 +01:00
if ( excludeArtistIds . Length ! = 0 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 04:29:46 +01:00
query . ExcludeArtistIds = excludeArtistIds ;
2020-07-03 18:39:50 +02:00
}
2020-11-17 04:29:46 +01:00
if ( albumIds . Length ! = 0 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 04:29:46 +01:00
query . AlbumIds = albumIds ;
2020-07-03 18:39:50 +02:00
}
// Albums
2020-11-17 04:37:43 +01:00
if ( albums . Length ! = 0 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 04:37:43 +01:00
query . AlbumIds = albums . SelectMany ( i = >
2020-07-03 18:39:50 +02:00
{
return _libraryManager . GetItemIds ( new InternalItemsQuery { IncludeItemTypes = new [ ] { nameof ( MusicAlbum ) } , Name = i , Limit = 1 } ) ;
} ) . ToArray ( ) ;
}
// Studios
2020-11-17 04:37:43 +01:00
if ( studios . Length ! = 0 )
2020-07-03 18:39:50 +02:00
{
2020-11-17 04:37:43 +01:00
query . StudioIds = studios . Select ( i = >
2020-07-03 18:39:50 +02:00
{
try
{
return _libraryManager . GetStudio ( i ) ;
}
catch
{
return null ;
}
} ) . Where ( i = > i ! = null ) . Select ( i = > i ! . Id ) . ToArray ( ) ;
}
// Apply default sorting if none requested
if ( query . OrderBy . Count = = 0 )
{
// Albums by artist
if ( query . ArtistIds . Length > 0 & & query . IncludeItemTypes . Length = = 1 & & string . Equals ( query . IncludeItemTypes [ 0 ] , "MusicAlbum" , StringComparison . OrdinalIgnoreCase ) )
{
query . OrderBy = new [ ] { new ValueTuple < string , SortOrder > ( ItemSortBy . ProductionYear , SortOrder . Descending ) , new ValueTuple < string , SortOrder > ( ItemSortBy . SortName , SortOrder . Ascending ) } ;
}
}
result = folder . GetItems ( query ) ;
}
else
{
var itemsArray = folder . GetChildren ( user , true ) ;
result = new QueryResult < BaseItem > { Items = itemsArray , TotalRecordCount = itemsArray . Count , StartIndex = 0 } ;
}
return new QueryResult < BaseItemDto > { StartIndex = startIndex . GetValueOrDefault ( ) , TotalRecordCount = result . TotalRecordCount , Items = _dtoService . GetBaseItemDtos ( result . Items , dtoOptions , user ) } ;
}
2020-11-15 18:58:39 +01:00
/// <summary>
/// Gets items based on a query.
/// </summary>
/// <param name="userId">The user id supplied as query parameter.</param>
/// <param name="maxOfficialRating">Optional filter by maximum official rating (PG, PG-13, TV-MA, etc).</param>
/// <param name="hasThemeSong">Optional filter by items with theme songs.</param>
/// <param name="hasThemeVideo">Optional filter by items with theme videos.</param>
/// <param name="hasSubtitles">Optional filter by items with subtitles.</param>
/// <param name="hasSpecialFeature">Optional filter by items with special features.</param>
/// <param name="hasTrailer">Optional filter by items with trailers.</param>
/// <param name="adjacentTo">Optional. Return items that are siblings of a supplied item.</param>
/// <param name="parentIndexNumber">Optional filter by parent index number.</param>
/// <param name="hasParentalRating">Optional filter by items that have or do not have a parental rating.</param>
/// <param name="isHd">Optional filter by items that are HD or not.</param>
/// <param name="is4K">Optional filter by items that are 4K or not.</param>
/// <param name="locationTypes">Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.</param>
/// <param name="excludeLocationTypes">Optional. If specified, results will be filtered based on the LocationType. This allows multiple, comma delimeted.</param>
/// <param name="isMissing">Optional filter by items that are missing episodes or not.</param>
/// <param name="isUnaired">Optional filter by items that are unaired episodes or not.</param>
/// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
/// <param name="minCriticRating">Optional filter by minimum critic rating.</param>
/// <param name="minPremiereDate">Optional. The minimum premiere date. Format = ISO.</param>
/// <param name="minDateLastSaved">Optional. The minimum last saved date. Format = ISO.</param>
/// <param name="minDateLastSavedForUser">Optional. The minimum last saved date for the current user. Format = ISO.</param>
/// <param name="maxPremiereDate">Optional. The maximum premiere date. Format = ISO.</param>
/// <param name="hasOverview">Optional filter by items that have an overview or not.</param>
/// <param name="hasImdbId">Optional filter by items that have an imdb id or not.</param>
/// <param name="hasTmdbId">Optional filter by items that have a tmdb id or not.</param>
/// <param name="hasTvdbId">Optional filter by items that have a tvdb id or not.</param>
/// <param name="excludeItemIds">Optional. If specified, results will be filtered by exxcluding item ids. This allows multiple, comma delimeted.</param>
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
/// <param name="limit">Optional. The maximum number of records to return.</param>
/// <param name="recursive">When searching within folders, this determines whether or not the search will be recursive. true/false.</param>
/// <param name="searchTerm">Optional. Filter based on a search term.</param>
/// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
/// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
/// <param name="excludeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.</param>
/// <param name="includeItemTypes">Optional. If specified, results will be filtered based on the item type. This allows multiple, comma delimeted.</param>
/// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
/// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
/// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
/// <param name="imageTypes">Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.</param>
/// <param name="sortBy">Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
/// <param name="isPlayed">Optional filter by items that are played, or not.</param>
/// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.</param>
/// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimeted.</param>
/// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimeted.</param>
/// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.</param>
/// <param name="enableUserData">Optional, include user data.</param>
/// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
/// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
/// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person id.</param>
/// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.</param>
/// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimeted.</param>
/// <param name="artists">Optional. If specified, results will be filtered based on artists. This allows multiple, pipe delimeted.</param>
/// <param name="excludeArtistIds">Optional. If specified, results will be filtered based on artist id. This allows multiple, pipe delimeted.</param>
/// <param name="artistIds">Optional. If specified, results will be filtered to include only those containing the specified artist id.</param>
/// <param name="albumArtistIds">Optional. If specified, results will be filtered to include only those containing the specified album artist id.</param>
/// <param name="contributingArtistIds">Optional. If specified, results will be filtered to include only those containing the specified contributing artist id.</param>
/// <param name="albums">Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.</param>
/// <param name="albumIds">Optional. If specified, results will be filtered based on album id. This allows multiple, pipe delimeted.</param>
/// <param name="ids">Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.</param>
/// <param name="videoTypes">Optional filter by VideoType (videofile, dvd, bluray, iso). Allows multiple, comma delimeted.</param>
/// <param name="minOfficialRating">Optional filter by minimum official rating (PG, PG-13, TV-MA, etc).</param>
/// <param name="isLocked">Optional filter by items that are locked.</param>
/// <param name="isPlaceHolder">Optional filter by items that are placeholders.</param>
/// <param name="hasOfficialRating">Optional filter by items that have official ratings.</param>
/// <param name="collapseBoxSetItems">Whether or not to hide items behind their boxsets.</param>
/// <param name="minWidth">Optional. Filter by the minimum width of the item.</param>
/// <param name="minHeight">Optional. Filter by the minimum height of the item.</param>
/// <param name="maxWidth">Optional. Filter by the maximum width of the item.</param>
/// <param name="maxHeight">Optional. Filter by the maximum height of the item.</param>
/// <param name="is3D">Optional filter by items that are 3D, or not.</param>
/// <param name="seriesStatus">Optional filter by Series Status. Allows multiple, comma delimeted.</param>
/// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a given input string.</param>
/// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</param>
/// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</param>
/// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimeted.</param>
/// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimeted.</param>
/// <param name="enableTotalRecordCount">Optional. Enable the total record count.</param>
/// <param name="enableImages">Optional, include image information in output.</param>
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the items.</returns>
[HttpGet("Users/{userId}/Items")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult < QueryResult < BaseItemDto > > GetItemsByUserId (
[FromRoute] Guid userId ,
[FromQuery] string? maxOfficialRating ,
[FromQuery] bool? hasThemeSong ,
[FromQuery] bool? hasThemeVideo ,
[FromQuery] bool? hasSubtitles ,
[FromQuery] bool? hasSpecialFeature ,
[FromQuery] bool? hasTrailer ,
[FromQuery] string? adjacentTo ,
[FromQuery] int? parentIndexNumber ,
[FromQuery] bool? hasParentalRating ,
[FromQuery] bool? isHd ,
[FromQuery] bool? is4K ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] LocationType [ ] locationTypes ,
2020-11-15 18:58:39 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] LocationType [ ] excludeLocationTypes ,
[FromQuery] bool? isMissing ,
[FromQuery] bool? isUnaired ,
[FromQuery] double? minCommunityRating ,
[FromQuery] double? minCriticRating ,
[FromQuery] DateTime ? minPremiereDate ,
[FromQuery] DateTime ? minDateLastSaved ,
[FromQuery] DateTime ? minDateLastSavedForUser ,
[FromQuery] DateTime ? maxPremiereDate ,
[FromQuery] bool? hasOverview ,
[FromQuery] bool? hasImdbId ,
[FromQuery] bool? hasTmdbId ,
[FromQuery] bool? hasTvdbId ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] excludeItemIds ,
2020-11-15 18:58:39 +01:00
[FromQuery] int? startIndex ,
[FromQuery] int? limit ,
[FromQuery] bool? recursive ,
[FromQuery] string? searchTerm ,
2021-01-24 01:32:13 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] SortOrder [ ] sortOrder ,
2020-12-01 19:07:41 +01:00
[FromQuery] Guid ? parentId ,
2020-11-15 18:58:39 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields [ ] fields ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] excludeItemTypes ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] includeItemTypes ,
2020-11-15 18:58:39 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter [ ] filters ,
[FromQuery] bool? isFavorite ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] mediaTypes ,
2020-11-15 18:58:39 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType [ ] imageTypes ,
2021-01-24 01:32:13 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] sortBy ,
2020-11-15 18:58:39 +01:00
[FromQuery] bool? isPlayed ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] genres ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] officialRatings ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] tags ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] int [ ] years ,
2020-11-15 18:58:39 +01:00
[FromQuery] bool? enableUserData ,
[FromQuery] int? imageTypeLimit ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType [ ] enableImageTypes ,
[FromQuery] string? person ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] personIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] personTypes ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] studios ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] artists ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] excludeArtistIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] artistIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] albumArtistIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] contributingArtistIds ,
[FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string [ ] albums ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] albumIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] ids ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] VideoType [ ] videoTypes ,
2020-11-15 18:58:39 +01:00
[FromQuery] string? minOfficialRating ,
[FromQuery] bool? isLocked ,
[FromQuery] bool? isPlaceHolder ,
[FromQuery] bool? hasOfficialRating ,
[FromQuery] bool? collapseBoxSetItems ,
[FromQuery] int? minWidth ,
[FromQuery] int? minHeight ,
[FromQuery] int? maxWidth ,
[FromQuery] int? maxHeight ,
[FromQuery] bool? is3D ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] SeriesStatus [ ] seriesStatus ,
2020-11-15 18:58:39 +01:00
[FromQuery] string? nameStartsWithOrGreater ,
[FromQuery] string? nameStartsWith ,
[FromQuery] string? nameLessThan ,
2020-11-20 18:50:11 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] studioIds ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid [ ] genreIds ,
2020-11-15 18:58:39 +01:00
[FromQuery] bool enableTotalRecordCount = true ,
[FromQuery] bool? enableImages = true )
{
return GetItems (
userId ,
maxOfficialRating ,
hasThemeSong ,
hasThemeVideo ,
hasSubtitles ,
hasSpecialFeature ,
hasTrailer ,
adjacentTo ,
parentIndexNumber ,
hasParentalRating ,
isHd ,
is4K ,
locationTypes ,
excludeLocationTypes ,
isMissing ,
isUnaired ,
minCommunityRating ,
minCriticRating ,
minPremiereDate ,
minDateLastSaved ,
minDateLastSavedForUser ,
maxPremiereDate ,
hasOverview ,
hasImdbId ,
hasTmdbId ,
hasTvdbId ,
excludeItemIds ,
startIndex ,
limit ,
recursive ,
searchTerm ,
sortOrder ,
parentId ,
fields ,
excludeItemTypes ,
includeItemTypes ,
filters ,
isFavorite ,
mediaTypes ,
imageTypes ,
sortBy ,
isPlayed ,
genres ,
officialRatings ,
tags ,
years ,
enableUserData ,
imageTypeLimit ,
enableImageTypes ,
person ,
personIds ,
personTypes ,
studios ,
artists ,
excludeArtistIds ,
artistIds ,
albumArtistIds ,
contributingArtistIds ,
albums ,
albumIds ,
ids ,
videoTypes ,
minOfficialRating ,
isLocked ,
isPlaceHolder ,
hasOfficialRating ,
collapseBoxSetItems ,
minWidth ,
minHeight ,
maxWidth ,
maxHeight ,
is3D ,
seriesStatus ,
nameStartsWithOrGreater ,
nameStartsWith ,
nameLessThan ,
studioIds ,
genreIds ,
enableTotalRecordCount ,
enableImages ) ;
}
2020-07-03 18:39:50 +02:00
/// <summary>
/// Gets items based on a query.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="startIndex">The start index.</param>
/// <param name="limit">The item limit.</param>
/// <param name="searchTerm">The search term.</param>
/// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
2020-11-18 14:23:45 +01:00
/// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
2020-07-03 18:39:50 +02:00
/// <param name="mediaTypes">Optional. Filter by MediaType. Allows multiple, comma delimited.</param>
/// <param name="enableUserData">Optional. Include user data.</param>
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
2020-11-18 14:23:45 +01:00
/// <param name="excludeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.</param>
/// <param name="includeItemTypes">Optional. If specified, results will be filtered based on the item type. This allows multiple, comma delimited.</param>
2020-07-03 18:39:50 +02:00
/// <param name="enableTotalRecordCount">Optional. Enable the total record count.</param>
/// <param name="enableImages">Optional. Include image information in output.</param>
/// <response code="200">Items returned.</response>
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the items that are resumable.</returns>
2020-08-04 20:48:53 +02:00
[HttpGet("Users/{userId}/Items/Resume")]
2020-07-03 18:39:50 +02:00
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult < QueryResult < BaseItemDto > > GetResumeItems (
2020-09-06 17:07:27 +02:00
[FromRoute, Required] Guid userId ,
2020-07-03 18:39:50 +02:00
[FromQuery] int? startIndex ,
[FromQuery] int? limit ,
[FromQuery] string? searchTerm ,
2020-12-01 19:07:41 +01:00
[FromQuery] Guid ? parentId ,
2020-11-09 22:59:04 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields [ ] fields ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] mediaTypes ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool? enableUserData ,
[FromQuery] int? imageTypeLimit ,
2020-11-09 22:53:23 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType [ ] enableImageTypes ,
2020-11-17 04:29:46 +01:00
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] excludeItemTypes ,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string [ ] includeItemTypes ,
2020-07-03 18:39:50 +02:00
[FromQuery] bool enableTotalRecordCount = true ,
[FromQuery] bool? enableImages = true )
{
var user = _userManager . GetUserById ( userId ) ;
2020-12-01 19:07:41 +01:00
var parentIdGuid = parentId ? ? Guid . Empty ;
2020-10-29 18:36:45 +01:00
var dtoOptions = new DtoOptions { Fields = fields }
2020-07-03 18:39:50 +02:00
. AddClientFields ( Request )
. AddAdditionalDtoOptions ( enableImages , enableUserData , imageTypeLimit , enableImageTypes ) ;
var ancestorIds = Array . Empty < Guid > ( ) ;
2020-12-13 16:15:26 +01:00
var excludeFolderIds = user . GetPreferenceValues < Guid > ( PreferenceKind . LatestItemExcludes ) ;
2020-07-03 18:39:50 +02:00
if ( parentIdGuid . Equals ( Guid . Empty ) & & excludeFolderIds . Length > 0 )
{
ancestorIds = _libraryManager . GetUserRootFolder ( ) . GetChildren ( user , true )
. Where ( i = > i is Folder )
2020-12-11 23:00:43 +01:00
. Where ( i = > ! excludeFolderIds . Contains ( i . Id ) )
2020-07-03 18:39:50 +02:00
. Select ( i = > i . Id )
. ToArray ( ) ;
}
var itemsResult = _libraryManager . GetItemsResult ( new InternalItemsQuery ( user )
{
OrderBy = new [ ] { ( ItemSortBy . DatePlayed , SortOrder . Descending ) } ,
IsResumable = true ,
StartIndex = startIndex ,
Limit = limit ,
ParentId = parentIdGuid ,
Recursive = true ,
DtoOptions = dtoOptions ,
2020-11-17 04:29:46 +01:00
MediaTypes = mediaTypes ,
2020-07-03 18:39:50 +02:00
IsVirtualItem = false ,
CollapseBoxSetItems = false ,
EnableTotalRecordCount = enableTotalRecordCount ,
AncestorIds = ancestorIds ,
2020-11-17 04:29:46 +01:00
IncludeItemTypes = includeItemTypes ,
ExcludeItemTypes = excludeItemTypes ,
2020-07-03 18:39:50 +02:00
SearchTerm = searchTerm
} ) ;
var returnItems = _dtoService . GetBaseItemDtos ( itemsResult . Items , dtoOptions , user ) ;
return new QueryResult < BaseItemDto >
{
StartIndex = startIndex . GetValueOrDefault ( ) ,
TotalRecordCount = itemsResult . TotalRecordCount ,
Items = returnItems
} ;
}
}
}