|
|
|
@ -12,6 +12,7 @@ using MediaBrowser.Controller.Library;
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
[Route("/Users/{UserId}/Suggestions", "GET", Summary = "Gets items based on a query.")]
|
|
|
|
|
[Route("/Users/{UserId}/Suggestions", "POST", Summary = "Gets items based on a query.")]
|
|
|
|
|
public class GetSuggestedItems : IReturn<QueryResult<BaseItem>>
|
|
|
|
|
{
|
|
|
|
|
public string MediaType { get; set; }
|
|
|
|
@ -20,6 +21,7 @@ namespace MediaBrowser.Api
|
|
|
|
|
public bool EnableTotalRecordCount { get; set; }
|
|
|
|
|
public int? StartIndex { get; set; }
|
|
|
|
|
public int? Limit { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public string[] GetMediaTypes()
|
|
|
|
|
{
|
|
|
|
@ -54,6 +56,13 @@ namespace MediaBrowser.Api
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<object> Post(GetSuggestedItems request)
|
|
|
|
|
{
|
|
|
|
|
var result = await GetResultItems(request).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<QueryResult<BaseItemDto>> GetResultItems(GetSuggestedItems request)
|
|
|
|
|
{
|
|
|
|
|
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
|
|
|
|
@ -77,7 +86,30 @@ namespace MediaBrowser.Api
|
|
|
|
|
|
|
|
|
|
private QueryResult<BaseItem> GetItems(GetSuggestedItems request, User user, DtoOptions dtoOptions)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
BaseItem similarToItem = null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(request.Name))
|
|
|
|
|
{
|
|
|
|
|
// get item by name, then get similar items from that
|
|
|
|
|
similarToItem = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
SortBy = new string[] {ItemSortBy.Random},
|
|
|
|
|
MediaTypes = request.GetMediaTypes(),
|
|
|
|
|
IncludeItemTypes = request.GetIncludeItemTypes(),
|
|
|
|
|
IsVirtualItem = false,
|
|
|
|
|
Name = request.Name,
|
|
|
|
|
Recursive = true,
|
|
|
|
|
Limit = 1
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (similarToItem == null)
|
|
|
|
|
{
|
|
|
|
|
return new QueryResult<BaseItem>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
SortBy = new string[] { ItemSortBy.Random },
|
|
|
|
|
MediaTypes = request.GetMediaTypes(),
|
|
|
|
@ -85,20 +117,11 @@ namespace MediaBrowser.Api
|
|
|
|
|
IsVirtualItem = false,
|
|
|
|
|
StartIndex = request.StartIndex,
|
|
|
|
|
Limit = request.Limit,
|
|
|
|
|
DtoOptions = dtoOptions
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (request.EnableTotalRecordCount)
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetItemsResult(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var items = _libraryManager.GetItemList(query).ToArray();
|
|
|
|
|
|
|
|
|
|
return new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
Items = items
|
|
|
|
|
};
|
|
|
|
|
DtoOptions = dtoOptions,
|
|
|
|
|
EnableTotalRecordCount = request.EnableTotalRecordCount,
|
|
|
|
|
Recursive = true,
|
|
|
|
|
SimilarTo = similarToItem
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|