Stub out new filtering api

This commit is contained in:
Luke Pulverenti 2017-12-03 17:15:21 -05:00
parent 8717f81bf4
commit 175c085d90
6 changed files with 151 additions and 10 deletions

View File

@ -5264,7 +5264,13 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
ItemIds = query.ItemIds, ItemIds = query.ItemIds,
TopParentIds = query.TopParentIds, TopParentIds = query.TopParentIds,
ParentId = query.ParentId, ParentId = query.ParentId,
IsPlayed = query.IsPlayed IsPlayed = query.IsPlayed,
IsAiring = query.IsAiring,
IsMovie = query.IsMovie,
IsSports = query.IsSports,
IsKids = query.IsKids,
IsNews = query.IsNews,
IsSeries = query.IsSeries
}; };
var innerWhereClauses = GetWhereClauses(innerQuery, null); var innerWhereClauses = GetWhereClauses(innerQuery, null);

View File

@ -125,7 +125,7 @@ namespace Emby.Server.Implementations.LiveTv
public void AddParts(IEnumerable<ILiveTvService> services, IEnumerable<ITunerHost> tunerHosts, IEnumerable<IListingsProvider> listingProviders) public void AddParts(IEnumerable<ILiveTvService> services, IEnumerable<ITunerHost> tunerHosts, IEnumerable<IListingsProvider> listingProviders)
{ {
_services = services.ToArray(); _services = services.ToArray();
_tunerHosts.AddRange(tunerHosts); _tunerHosts.AddRange(tunerHosts.Where(i => i.IsSupported));
_listingProviders.AddRange(listingProviders); _listingProviders.AddRange(listingProviders);
foreach (var service in _services) foreach (var service in _services)
@ -947,6 +947,7 @@ namespace Emby.Server.Implementations.LiveTv
IsKids = query.IsKids, IsKids = query.IsKids,
IsNews = query.IsNews, IsNews = query.IsNews,
Genres = query.Genres, Genres = query.Genres,
GenreIds = query.GenreIds,
StartIndex = query.StartIndex, StartIndex = query.StartIndex,
Limit = query.Limit, Limit = query.Limit,
OrderBy = query.OrderBy, OrderBy = query.OrderBy,

View File

@ -2,6 +2,7 @@
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Dto;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,7 +12,7 @@ using MediaBrowser.Model.Services;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
[Route("/Items/Filters", "GET", Summary = "Gets branding configuration")] [Route("/Items/Filters", "GET", Summary = "Gets branding configuration")]
public class GetQueryFilters : IReturn<QueryFilters> public class GetQueryFiltersLegacy : IReturn<QueryFiltersLegacy>
{ {
/// <summary> /// <summary>
/// Gets or sets the user id. /// Gets or sets the user id.
@ -40,6 +41,43 @@ namespace MediaBrowser.Api
} }
} }
[Route("/Items/Filters2", "GET", Summary = "Gets branding configuration")]
public class GetQueryFilters : IReturn<QueryFilters>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get; set; }
[ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ParentId { get; set; }
[ApiMember(Name = "IncludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string IncludeItemTypes { get; set; }
[ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string MediaTypes { get; set; }
public string[] GetMediaTypes()
{
return (MediaTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public string[] GetIncludeItemTypes()
{
return (IncludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public bool? IsAiring { get; set; }
public bool? IsMovie { get; set; }
public bool? IsSports { get; set; }
public bool? IsKids { get; set; }
public bool? IsNews { get; set; }
public bool? IsSeries { get; set; }
}
[Authenticated] [Authenticated]
public class FilterService : BaseApiService public class FilterService : BaseApiService
{ {
@ -57,18 +95,96 @@ namespace MediaBrowser.Api
var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId); var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId);
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null; var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, typeof(Trailer).Name, StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "Program", StringComparison.OrdinalIgnoreCase))
{
parentItem = null;
}
var filters = new QueryFilters();
var genreQuery = new InternalItemsQuery(user)
{
AncestorIds = parentItem == null ? new string[] { } : new string[] { parentItem.Id.ToString("N") },
IncludeItemTypes = request.GetIncludeItemTypes(),
DtoOptions = new Controller.Dto.DtoOptions
{
Fields = new ItemFields[] { },
EnableImages = false,
EnableUserData = false
},
IsAiring = request.IsAiring,
IsMovie = request.IsMovie,
IsSports = request.IsSports,
IsKids = request.IsKids,
IsNews = request.IsNews,
IsSeries = request.IsSeries
};
if (string.Equals(request.IncludeItemTypes, "MusicAlbum", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "MusicVideo", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "MusicArtist", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "Audio", StringComparison.OrdinalIgnoreCase))
{
filters.Genres = _libraryManager.GetMusicGenres(genreQuery).Items.Select(i => new NameIdPair
{
Name = i.Item1.Name,
Id = i.Item1.Id.ToString("N")
}).ToArray();
}
else if (string.Equals(request.IncludeItemTypes, "Game", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "GameSystem", StringComparison.OrdinalIgnoreCase))
{
filters.Genres = _libraryManager.GetGameGenres(genreQuery).Items.Select(i => new NameIdPair
{
Name = i.Item1.Name,
Id = i.Item1.Id.ToString("N")
}).ToArray();
}
else
{
filters.Genres = _libraryManager.GetGenres(genreQuery).Items.Select(i => new NameIdPair
{
Name = i.Item1.Name,
Id = i.Item1.Id.ToString("N")
}).ToArray();
}
return ToOptimizedResult(filters);
}
public object Get(GetQueryFiltersLegacy request)
{
var parentItem = string.IsNullOrEmpty(request.ParentId) ? null : _libraryManager.GetItemById(request.ParentId);
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, typeof(Trailer).Name, StringComparison.OrdinalIgnoreCase) ||
string.Equals(request.IncludeItemTypes, "Program", StringComparison.OrdinalIgnoreCase))
{
parentItem = null;
}
var item = string.IsNullOrEmpty(request.ParentId) ? var item = string.IsNullOrEmpty(request.ParentId) ?
user == null ? _libraryManager.RootFolder : user.RootFolder : user == null ? _libraryManager.RootFolder : user.RootFolder :
parentItem; parentItem;
var result = ((Folder)item).GetItemList(GetItemsQuery(request, user)); var result = ((Folder)item).GetItemList(GetItemsQuery(request, user));
return ToOptimizedResult(GetFilters(result)); var filters = GetFilters(result);
return ToOptimizedResult(filters);
} }
private QueryFilters GetFilters(BaseItem[] items) private QueryFiltersLegacy GetFilters(BaseItem[] items)
{ {
var result = new QueryFilters(); var result = new QueryFiltersLegacy();
result.Years = items.Select(i => i.ProductionYear ?? -1) result.Years = items.Select(i => i.ProductionYear ?? -1)
.Where(i => i > 0) .Where(i => i > 0)
@ -97,7 +213,7 @@ namespace MediaBrowser.Api
return result; return result;
} }
private InternalItemsQuery GetItemsQuery(GetQueryFilters request, User user) private InternalItemsQuery GetItemsQuery(GetQueryFiltersLegacy request, User user)
{ {
var query = new InternalItemsQuery var query = new InternalItemsQuery
{ {

View File

@ -379,6 +379,9 @@ namespace MediaBrowser.Api.LiveTv
[ApiMember(Name = "Genres", Description = "The genres to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")] [ApiMember(Name = "Genres", Description = "The genres to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
public string Genres { get; set; } public string Genres { get; set; }
[ApiMember(Name = "GenreIds", Description = "The genres to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")]
public string GenreIds { get; set; }
[ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? EnableImages { get; set; } public bool? EnableImages { get; set; }
@ -1003,6 +1006,7 @@ namespace MediaBrowser.Api.LiveTv
query.IsSports = request.IsSports; query.IsSports = request.IsSports;
query.SeriesTimerId = request.SeriesTimerId; query.SeriesTimerId = request.SeriesTimerId;
query.Genres = (request.Genres ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); query.Genres = (request.Genres ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
query.GenreIds = (request.GenreIds ?? String.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
if (!string.IsNullOrWhiteSpace(request.LibrarySeriesId)) if (!string.IsNullOrWhiteSpace(request.LibrarySeriesId))
{ {

View File

@ -14,6 +14,7 @@ namespace MediaBrowser.Model.LiveTv
ChannelIds = new string[] { }; ChannelIds = new string[] { };
OrderBy = new Tuple<string, SortOrder>[] { }; OrderBy = new Tuple<string, SortOrder>[] { };
Genres = new string[] { }; Genres = new string[] { };
GenreIds = new string[] { };
EnableTotalRecordCount = true; EnableTotalRecordCount = true;
EnableUserData = true; EnableUserData = true;
} }
@ -110,6 +111,7 @@ namespace MediaBrowser.Model.LiveTv
/// Limit results to items containing specific genres /// Limit results to items containing specific genres
/// </summary> /// </summary>
/// <value>The genres.</value> /// <value>The genres.</value>
public string[] GenreIds { get; set; }
public string[] Genres { get; set; } public string[] Genres { get; set; }
} }
} }

View File

@ -1,14 +1,15 @@
 using MediaBrowser.Model.Dto;
namespace MediaBrowser.Model.Querying namespace MediaBrowser.Model.Querying
{ {
public class QueryFilters public class QueryFiltersLegacy
{ {
public string[] Genres { get; set; } public string[] Genres { get; set; }
public string[] Tags { get; set; } public string[] Tags { get; set; }
public string[] OfficialRatings { get; set; } public string[] OfficialRatings { get; set; }
public int[] Years { get; set; } public int[] Years { get; set; }
public QueryFilters() public QueryFiltersLegacy()
{ {
Genres = new string[] { }; Genres = new string[] { };
Tags = new string[] { }; Tags = new string[] { };
@ -16,4 +17,15 @@ namespace MediaBrowser.Model.Querying
Years = new int[] { }; Years = new int[] { };
} }
} }
public class QueryFilters
{
public NameIdPair[] Genres { get; set; }
public string[] Tags { get; set; }
public QueryFilters()
{
Tags = new string[] { };
Genres = new NameIdPair[] { };
}
}
} }