2019-01-13 21:01:16 +01:00
|
|
|
using System;
|
2013-02-21 02:33:05 +01:00
|
|
|
using System.Collections.Generic;
|
2013-12-29 00:09:24 +01:00
|
|
|
using System.Globalization;
|
2013-02-21 02:33:05 +01:00
|
|
|
using System.Linq;
|
2019-01-13 20:24:58 +01:00
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2017-02-18 09:32:17 +01:00
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2019-01-13 20:24:58 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Net;
|
2017-08-19 21:43:35 +02:00
|
|
|
using MediaBrowser.Model.Dto;
|
2019-01-13 20:24:58 +01:00
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-24 04:45:23 +02:00
|
|
|
using MediaBrowser.Model.Globalization;
|
2019-01-13 20:24:58 +01:00
|
|
|
using MediaBrowser.Model.Querying;
|
2016-10-25 21:02:04 +02:00
|
|
|
using MediaBrowser.Model.Services;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
|
|
namespace MediaBrowser.Api.UserLibrary
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class GetItems
|
|
|
|
/// </summary>
|
2014-03-28 20:58:18 +01:00
|
|
|
[Route("/Items", "GET", Summary = "Gets items based on a query.")]
|
|
|
|
[Route("/Users/{UserId}/Items", "GET", Summary = "Gets items based on a query.")]
|
2017-08-19 21:43:35 +02:00
|
|
|
public class GetItems : BaseItemsRequest, IReturn<QueryResult<BaseItemDto>>
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-01 19:26:09 +02:00
|
|
|
[Route("/Users/{UserId}/Items/Resume", "GET", Summary = "Gets items based on a query.")]
|
|
|
|
public class GetResumeItems : BaseItemsRequest, IReturn<QueryResult<BaseItemDto>>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Class ItemsService
|
|
|
|
/// </summary>
|
2014-07-02 20:34:08 +02:00
|
|
|
[Authenticated]
|
2013-03-16 06:52:33 +01:00
|
|
|
public class ItemsService : BaseApiService
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2013-02-27 21:25:45 +01:00
|
|
|
/// <summary>
|
|
|
|
/// The _user manager
|
|
|
|
/// </summary>
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
2013-02-28 20:32:41 +01:00
|
|
|
/// <summary>
|
|
|
|
/// The _library manager
|
|
|
|
/// </summary>
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-06-10 19:46:11 +02:00
|
|
|
private readonly ILocalizationManager _localization;
|
2013-03-09 06:15:51 +01:00
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
private readonly IDtoService _dtoService;
|
2016-11-10 15:41:24 +01:00
|
|
|
private readonly IAuthorizationContext _authContext;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
2013-02-27 21:25:45 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ItemsService" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
2013-03-28 23:00:58 +01:00
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
2014-04-22 19:25:54 +02:00
|
|
|
/// <param name="localization">The localization.</param>
|
|
|
|
/// <param name="dtoService">The dto service.</param>
|
2016-11-10 15:41:24 +01:00
|
|
|
public ItemsService(IUserManager userManager, ILibraryManager libraryManager, ILocalizationManager localization, IDtoService dtoService, IAuthorizationContext authContext)
|
2013-02-27 21:25:45 +01:00
|
|
|
{
|
2016-06-26 22:35:03 +02:00
|
|
|
if (userManager == null)
|
|
|
|
{
|
2019-01-06 21:50:43 +01:00
|
|
|
throw new ArgumentNullException(nameof(userManager));
|
2016-06-26 22:35:03 +02:00
|
|
|
}
|
|
|
|
if (libraryManager == null)
|
|
|
|
{
|
2019-01-06 21:50:43 +01:00
|
|
|
throw new ArgumentNullException(nameof(libraryManager));
|
2016-06-26 22:35:03 +02:00
|
|
|
}
|
|
|
|
if (localization == null)
|
|
|
|
{
|
2019-01-06 21:50:43 +01:00
|
|
|
throw new ArgumentNullException(nameof(localization));
|
2016-06-26 22:35:03 +02:00
|
|
|
}
|
|
|
|
if (dtoService == null)
|
|
|
|
{
|
2019-01-06 21:50:43 +01:00
|
|
|
throw new ArgumentNullException(nameof(dtoService));
|
2016-06-26 22:35:03 +02:00
|
|
|
}
|
|
|
|
|
2013-02-27 21:25:45 +01:00
|
|
|
_userManager = userManager;
|
2013-02-28 20:32:41 +01:00
|
|
|
_libraryManager = libraryManager;
|
2013-06-13 20:17:59 +02:00
|
|
|
_localization = localization;
|
2013-09-04 19:02:19 +02:00
|
|
|
_dtoService = dtoService;
|
2016-11-10 15:41:24 +01:00
|
|
|
_authContext = authContext;
|
2013-02-27 21:25:45 +01:00
|
|
|
}
|
|
|
|
|
2017-10-01 19:26:09 +02:00
|
|
|
public object Get(GetResumeItems request)
|
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
var parentIdGuid = string.IsNullOrWhiteSpace(request.ParentId) ? Guid.Empty : new Guid(request.ParentId);
|
2017-10-01 19:26:09 +02:00
|
|
|
|
|
|
|
var options = GetDtoOptions(_authContext, request);
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
var ancestorIds = new List<Guid>();
|
2017-10-01 19:26:09 +02:00
|
|
|
|
|
|
|
var excludeFolderIds = user.Configuration.LatestItemsExcludes;
|
2018-09-12 19:26:21 +02:00
|
|
|
if (parentIdGuid.Equals(Guid.Empty) && excludeFolderIds.Length > 0)
|
2017-10-01 19:26:09 +02:00
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
ancestorIds = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
2017-10-01 19:26:09 +02:00
|
|
|
.Where(i => i is Folder)
|
|
|
|
.Where(i => !excludeFolderIds.Contains(i.Id.ToString("N")))
|
2018-09-12 19:26:21 +02:00
|
|
|
.Select(i => i.Id)
|
2017-10-01 19:26:09 +02:00
|
|
|
.ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
OrderBy = new[] { ItemSortBy.DatePlayed }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(),
|
2017-10-01 19:26:09 +02:00
|
|
|
IsResumable = true,
|
|
|
|
StartIndex = request.StartIndex,
|
|
|
|
Limit = request.Limit,
|
|
|
|
ParentId = parentIdGuid,
|
|
|
|
Recursive = true,
|
|
|
|
DtoOptions = options,
|
|
|
|
MediaTypes = request.GetMediaTypes(),
|
|
|
|
IsVirtualItem = false,
|
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
EnableTotalRecordCount = request.EnableTotalRecordCount,
|
2017-10-04 20:51:26 +02:00
|
|
|
AncestorIds = ancestorIds.ToArray(),
|
|
|
|
IncludeItemTypes = request.GetIncludeItemTypes(),
|
2018-09-12 19:26:21 +02:00
|
|
|
ExcludeItemTypes = request.GetExcludeItemTypes(),
|
|
|
|
SearchTerm = request.SearchTerm
|
2017-10-01 19:26:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var returnItems = _dtoService.GetBaseItemDtos(itemsResult.Items, options, user);
|
|
|
|
|
|
|
|
var result = new QueryResult<BaseItemDto>
|
|
|
|
{
|
|
|
|
TotalRecordCount = itemsResult.TotalRecordCount,
|
|
|
|
Items = returnItems
|
|
|
|
};
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
return ToOptimizedResult(result);
|
2017-10-01 19:26:09 +02:00
|
|
|
}
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>System.Object.</returns>
|
2017-08-28 02:33:05 +02:00
|
|
|
public object Get(GetItems request)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2016-06-26 22:35:03 +02:00
|
|
|
if (request == null)
|
|
|
|
{
|
2019-01-06 21:50:43 +01:00
|
|
|
throw new ArgumentNullException(nameof(request));
|
2016-06-26 22:35:03 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
var result = GetItems(request);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
return ToOptimizedResult(result);
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the items.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
2017-08-28 02:33:05 +02:00
|
|
|
private QueryResult<BaseItemDto> GetItems(GetItems request)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2019-02-08 22:59:28 +01:00
|
|
|
var user = request.UserId == Guid.Empty ? null : _userManager.GetUserById(request.UserId);
|
2016-10-08 07:57:38 +02:00
|
|
|
|
2016-11-10 15:41:24 +01:00
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
2016-10-08 07:57:38 +02:00
|
|
|
|
2017-05-26 08:48:54 +02:00
|
|
|
var result = GetQueryResult(request, dtoOptions, user);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2016-06-26 22:35:03 +02:00
|
|
|
if (result == null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("GetItemsToSerialize returned null");
|
|
|
|
}
|
|
|
|
|
2016-06-26 22:38:50 +02:00
|
|
|
if (result.Items == null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("GetItemsToSerialize result.Items returned null");
|
|
|
|
}
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user);
|
2016-06-26 22:35:03 +02:00
|
|
|
|
|
|
|
if (dtoList == null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("GetBaseItemDtos returned null");
|
|
|
|
}
|
|
|
|
|
2017-08-19 21:43:35 +02:00
|
|
|
return new QueryResult<BaseItemDto>
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2016-03-20 07:46:51 +01:00
|
|
|
TotalRecordCount = result.TotalRecordCount,
|
2017-08-19 21:43:35 +02:00
|
|
|
Items = dtoList
|
2013-02-21 02:33:05 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the items to serialize.
|
|
|
|
/// </summary>
|
2017-05-26 08:48:54 +02:00
|
|
|
private QueryResult<BaseItem> GetQueryResult(GetItems request, DtoOptions dtoOptions, User user)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2019-02-08 22:59:28 +01:00
|
|
|
if (string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|| string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase))
|
2016-02-05 18:04:38 +01:00
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
request.ParentId = null;
|
2016-02-05 18:04:38 +01:00
|
|
|
}
|
2015-11-15 23:30:47 +01:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
var item = string.IsNullOrEmpty(request.ParentId) ?
|
|
|
|
null :
|
|
|
|
_libraryManager.GetItemById(request.ParentId);
|
|
|
|
|
2016-10-12 20:23:09 +02:00
|
|
|
if (item == null)
|
|
|
|
{
|
|
|
|
item = string.IsNullOrEmpty(request.ParentId) ?
|
2018-09-12 19:26:21 +02:00
|
|
|
user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder() :
|
2016-10-12 20:23:09 +02:00
|
|
|
_libraryManager.GetItemById(request.ParentId);
|
|
|
|
}
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
// Default list type = children
|
|
|
|
|
2016-06-23 19:04:18 +02:00
|
|
|
var folder = item as Folder;
|
|
|
|
if (folder == null)
|
|
|
|
{
|
|
|
|
folder = user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder();
|
|
|
|
}
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
var hasCollectionType = folder as IHasCollectionType;
|
|
|
|
var isPlaylistQuery = (hasCollectionType != null && string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
if (isPlaylistQuery)
|
|
|
|
{
|
|
|
|
request.Recursive = true;
|
|
|
|
request.IncludeItemTypes = "Playlist";
|
|
|
|
}
|
|
|
|
|
2016-08-18 18:45:36 +02:00
|
|
|
if (request.Recursive || !string.IsNullOrEmpty(request.Ids) || user == null)
|
2013-10-16 00:16:39 +02:00
|
|
|
{
|
2017-05-26 08:48:54 +02:00
|
|
|
return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
|
2013-10-16 00:16:39 +02:00
|
|
|
}
|
2015-07-14 21:04:16 +02:00
|
|
|
|
|
|
|
var userRoot = item as UserRootFolder;
|
2014-10-07 01:58:46 +02:00
|
|
|
|
2015-07-14 21:04:16 +02:00
|
|
|
if (userRoot == null)
|
|
|
|
{
|
2017-05-26 08:48:54 +02:00
|
|
|
return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
2017-08-19 21:43:35 +02:00
|
|
|
var itemsArray = folder.GetChildren(user, true).ToArray();
|
2015-07-14 21:04:16 +02:00
|
|
|
|
2016-03-20 07:46:51 +01:00
|
|
|
return new QueryResult<BaseItem>
|
2014-10-07 01:58:46 +02:00
|
|
|
{
|
2015-07-14 21:04:16 +02:00
|
|
|
Items = itemsArray,
|
|
|
|
TotalRecordCount = itemsArray.Length
|
2016-03-20 07:46:51 +01:00
|
|
|
};
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 07:57:38 +02:00
|
|
|
private InternalItemsQuery GetItemsQuery(GetItems request, DtoOptions dtoOptions, User user)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2016-03-20 07:46:51 +01:00
|
|
|
var query = new InternalItemsQuery(user)
|
2014-10-07 01:58:46 +02:00
|
|
|
{
|
|
|
|
IsPlayed = request.IsPlayed,
|
|
|
|
MediaTypes = request.GetMediaTypes(),
|
|
|
|
IncludeItemTypes = request.GetIncludeItemTypes(),
|
|
|
|
ExcludeItemTypes = request.GetExcludeItemTypes(),
|
|
|
|
Recursive = request.Recursive,
|
2017-09-04 21:28:22 +02:00
|
|
|
OrderBy = request.GetOrderBy(),
|
2014-10-07 01:58:46 +02:00
|
|
|
|
2016-01-12 03:22:52 +01:00
|
|
|
IsFavorite = request.IsFavorite,
|
2014-10-07 01:58:46 +02:00
|
|
|
Limit = request.Limit,
|
2014-10-08 03:37:45 +02:00
|
|
|
StartIndex = request.StartIndex,
|
|
|
|
IsMissing = request.IsMissing,
|
|
|
|
IsUnaired = request.IsUnaired,
|
|
|
|
CollapseBoxSetItems = request.CollapseBoxSetItems,
|
|
|
|
NameLessThan = request.NameLessThan,
|
|
|
|
NameStartsWith = request.NameStartsWith,
|
|
|
|
NameStartsWithOrGreater = request.NameStartsWithOrGreater,
|
|
|
|
HasImdbId = request.HasImdbId,
|
|
|
|
IsPlaceHolder = request.IsPlaceHolder,
|
|
|
|
IsLocked = request.IsLocked,
|
2018-09-12 19:26:21 +02:00
|
|
|
MinWidth = request.MinWidth,
|
|
|
|
MinHeight = request.MinHeight,
|
|
|
|
MaxWidth = request.MaxWidth,
|
|
|
|
MaxHeight = request.MaxHeight,
|
2014-10-08 03:37:45 +02:00
|
|
|
Is3D = request.Is3D,
|
|
|
|
HasTvdbId = request.HasTvdbId,
|
|
|
|
HasTmdbId = request.HasTmdbId,
|
|
|
|
HasOverview = request.HasOverview,
|
|
|
|
HasOfficialRating = request.HasOfficialRating,
|
|
|
|
HasParentalRating = request.HasParentalRating,
|
|
|
|
HasSpecialFeature = request.HasSpecialFeature,
|
|
|
|
HasSubtitles = request.HasSubtitles,
|
|
|
|
HasThemeSong = request.HasThemeSong,
|
|
|
|
HasThemeVideo = request.HasThemeVideo,
|
|
|
|
HasTrailer = request.HasTrailer,
|
2018-09-12 19:26:21 +02:00
|
|
|
IsHD = request.IsHD,
|
|
|
|
Is4K = request.Is4K,
|
2014-11-10 05:20:11 +01:00
|
|
|
Tags = request.GetTags(),
|
|
|
|
OfficialRatings = request.GetOfficialRatings(),
|
2014-10-08 03:37:45 +02:00
|
|
|
Genres = request.GetGenres(),
|
2018-09-12 19:26:21 +02:00
|
|
|
ArtistIds = GetGuids(request.ArtistIds),
|
|
|
|
AlbumArtistIds = GetGuids(request.AlbumArtistIds),
|
|
|
|
ContributingArtistIds = GetGuids(request.ContributingArtistIds),
|
|
|
|
GenreIds = GetGuids(request.GenreIds),
|
|
|
|
StudioIds = GetGuids(request.StudioIds),
|
2014-10-08 03:37:45 +02:00
|
|
|
Person = request.Person,
|
2018-09-12 19:26:21 +02:00
|
|
|
PersonIds = GetGuids(request.PersonIds),
|
2014-10-08 03:37:45 +02:00
|
|
|
PersonTypes = request.GetPersonTypes(),
|
|
|
|
Years = request.GetYears(),
|
2017-08-09 21:56:38 +02:00
|
|
|
ImageTypes = request.GetImageTypes(),
|
|
|
|
VideoTypes = request.GetVideoTypes(),
|
2015-07-14 21:04:16 +02:00
|
|
|
AdjacentTo = request.AdjacentTo,
|
2018-09-12 19:26:21 +02:00
|
|
|
ItemIds = GetGuids(request.Ids),
|
2015-07-14 21:04:16 +02:00
|
|
|
MinCommunityRating = request.MinCommunityRating,
|
2016-03-20 07:46:51 +01:00
|
|
|
MinCriticRating = request.MinCriticRating,
|
2018-09-12 19:26:21 +02:00
|
|
|
ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? Guid.Empty : new Guid(request.ParentId),
|
2016-03-20 21:04:27 +01:00
|
|
|
ParentIndexNumber = request.ParentIndexNumber,
|
2016-07-22 07:38:01 +02:00
|
|
|
EnableTotalRecordCount = request.EnableTotalRecordCount,
|
2018-09-12 19:26:21 +02:00
|
|
|
ExcludeItemIds = GetGuids(request.ExcludeItemIds),
|
|
|
|
DtoOptions = dtoOptions,
|
|
|
|
SearchTerm = request.SearchTerm
|
2014-10-07 01:58:46 +02:00
|
|
|
};
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
if (!string.IsNullOrWhiteSpace(request.Ids) || !string.IsNullOrWhiteSpace(request.SearchTerm))
|
2014-10-08 03:37:45 +02:00
|
|
|
{
|
|
|
|
query.CollapseBoxSetItems = false;
|
|
|
|
}
|
|
|
|
|
2014-10-07 01:58:46 +02:00
|
|
|
foreach (var filter in request.GetFilters())
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2017-05-23 18:43:24 +02:00
|
|
|
if (!string.IsNullOrEmpty(request.MinDateLastSaved))
|
|
|
|
{
|
|
|
|
query.MinDateLastSaved = DateTime.Parse(request.MinDateLastSaved, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(request.MinDateLastSavedForUser))
|
|
|
|
{
|
|
|
|
query.MinDateLastSavedForUser = DateTime.Parse(request.MinDateLastSavedForUser, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
}
|
|
|
|
|
2016-03-20 07:46:51 +01:00
|
|
|
if (!string.IsNullOrEmpty(request.MinPremiereDate))
|
|
|
|
{
|
|
|
|
query.MinPremiereDate = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(request.MaxPremiereDate))
|
|
|
|
{
|
|
|
|
query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
}
|
|
|
|
|
2016-03-20 20:53:22 +01:00
|
|
|
// Filter by Series Status
|
|
|
|
if (!string.IsNullOrEmpty(request.SeriesStatus))
|
|
|
|
{
|
|
|
|
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExcludeLocationTypes
|
|
|
|
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
|
|
|
|
{
|
2017-01-09 18:05:34 +01:00
|
|
|
var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
|
|
|
|
if (excludeLocationTypes.Contains(LocationType.Virtual))
|
|
|
|
{
|
|
|
|
query.IsVirtualItem = false;
|
|
|
|
}
|
2016-03-20 20:53:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(request.LocationTypes))
|
|
|
|
{
|
2017-05-06 07:18:54 +02:00
|
|
|
var requestedLocationTypes =
|
2017-08-19 21:43:35 +02:00
|
|
|
request.LocationTypes.Split(',');
|
2017-05-06 07:18:54 +02:00
|
|
|
|
2017-08-19 21:43:35 +02:00
|
|
|
if (requestedLocationTypes.Length > 0 && requestedLocationTypes.Length < 4)
|
2017-05-06 07:18:54 +02:00
|
|
|
{
|
2017-08-19 21:43:35 +02:00
|
|
|
query.IsVirtualItem = requestedLocationTypes.Contains(LocationType.Virtual.ToString());
|
2017-05-06 07:18:54 +02:00
|
|
|
}
|
2016-03-20 20:53:22 +01:00
|
|
|
}
|
2016-06-25 02:29:39 +02:00
|
|
|
|
2016-03-21 04:10:37 +01:00
|
|
|
// Min official rating
|
2016-04-27 19:50:32 +02:00
|
|
|
if (!string.IsNullOrWhiteSpace(request.MinOfficialRating))
|
2016-03-21 04:10:37 +01:00
|
|
|
{
|
|
|
|
query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Max official rating
|
2016-04-27 19:50:32 +02:00
|
|
|
if (!string.IsNullOrWhiteSpace(request.MaxOfficialRating))
|
2016-03-21 04:10:37 +01:00
|
|
|
{
|
2016-04-27 19:50:32 +02:00
|
|
|
query.MaxParentalRating = _localization.GetRatingLevel(request.MaxOfficialRating);
|
2016-03-21 04:10:37 +01:00
|
|
|
}
|
2016-03-20 20:53:22 +01:00
|
|
|
|
2016-03-21 17:50:50 +01:00
|
|
|
// Artists
|
|
|
|
if (!string.IsNullOrEmpty(request.Artists))
|
|
|
|
{
|
2016-12-20 20:59:25 +01:00
|
|
|
query.ArtistIds = request.Artists.Split('|').Select(i =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-05-22 06:54:02 +02:00
|
|
|
return _libraryManager.GetArtist(i, new DtoOptions(false));
|
2016-12-20 20:59:25 +01:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2018-09-12 19:26:21 +02:00
|
|
|
}).Where(i => i != null).Select(i => i.Id).ToArray();
|
2016-03-21 17:50:50 +01:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:10:39 +02:00
|
|
|
// ExcludeArtistIds
|
2017-02-18 09:32:17 +01:00
|
|
|
if (!string.IsNullOrWhiteSpace(request.ExcludeArtistIds))
|
2016-07-22 19:54:43 +02:00
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
query.ExcludeArtistIds = GetGuids(request.ExcludeArtistIds);
|
2016-07-22 19:54:43 +02:00
|
|
|
}
|
|
|
|
|
2017-02-18 09:32:17 +01:00
|
|
|
if (!string.IsNullOrWhiteSpace(request.AlbumIds))
|
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
query.AlbumIds = GetGuids(request.AlbumIds);
|
2017-02-18 09:32:17 +01:00
|
|
|
}
|
|
|
|
|
2016-03-21 17:50:50 +01:00
|
|
|
// Albums
|
|
|
|
if (!string.IsNullOrEmpty(request.Albums))
|
|
|
|
{
|
2017-05-21 09:25:49 +02:00
|
|
|
query.AlbumIds = request.Albums.Split('|').SelectMany(i =>
|
2017-02-18 09:32:17 +01:00
|
|
|
{
|
2017-05-21 09:25:49 +02:00
|
|
|
return _libraryManager.GetItemIds(new InternalItemsQuery
|
2017-02-18 09:32:17 +01:00
|
|
|
{
|
|
|
|
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
|
|
|
|
Name = i,
|
|
|
|
Limit = 1
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
}).Select(albumId => albumId);
|
2017-02-18 09:32:17 +01:00
|
|
|
|
|
|
|
}).ToArray();
|
2016-03-21 17:50:50 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 20:59:25 +01:00
|
|
|
// Studios
|
|
|
|
if (!string.IsNullOrEmpty(request.Studios))
|
|
|
|
{
|
|
|
|
query.StudioIds = request.Studios.Split('|').Select(i =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return _libraryManager.GetStudio(i);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2018-09-12 19:26:21 +02:00
|
|
|
}).Where(i => i != null).Select(i => i.Id).ToArray();
|
2016-12-20 20:59:25 +01:00
|
|
|
}
|
|
|
|
|
2017-09-07 20:17:18 +02:00
|
|
|
// Apply default sorting if none requested
|
|
|
|
if (query.OrderBy.Length == 0)
|
|
|
|
{
|
|
|
|
// Albums by artist
|
|
|
|
if (query.ArtistIds.Length > 0 && query.IncludeItemTypes.Length == 1 && string.Equals(query.IncludeItemTypes[0], "MusicAlbum", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2019-01-13 20:24:58 +01:00
|
|
|
query.OrderBy = new[]
|
2017-09-07 20:17:18 +02:00
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
new ValueTuple<string, SortOrder>(ItemSortBy.ProductionYear, SortOrder.Descending),
|
|
|
|
new ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending)
|
2017-09-07 20:17:18 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-07 01:58:46 +02:00
|
|
|
return query;
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class DateCreatedComparer
|
|
|
|
/// </summary>
|
|
|
|
public class DateCreatedComparer : IComparer<BaseItem>
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Compares the specified x.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="x">The x.</param>
|
|
|
|
/// <param name="y">The y.</param>
|
|
|
|
/// <returns>System.Int32.</returns>
|
|
|
|
public int Compare(BaseItem x, BaseItem y)
|
|
|
|
{
|
|
|
|
return x.DateCreated.CompareTo(y.DateCreated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|