Added GetItemsWithPerson
This commit is contained in:
parent
ee1fa6e816
commit
0788f435c1
32
MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs
Normal file
32
MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all items within containing a person
|
||||
/// </summary>
|
||||
public class ItemsWithPersonHandler : ItemListHandler
|
||||
{
|
||||
protected override IEnumerable<BaseItem> ItemsToSerialize
|
||||
{
|
||||
get
|
||||
{
|
||||
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
|
||||
|
||||
PersonType? personType = null;
|
||||
|
||||
string type = QueryString["persontype"];
|
||||
|
||||
if (!string.IsNullOrEmpty(type))
|
||||
{
|
||||
personType = (PersonType)Enum.Parse(typeof(PersonType), type, true);
|
||||
}
|
||||
|
||||
return Kernel.Instance.GetItemsWithPerson(parent, QueryString["name"], personType, UserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@
|
|||
<Compile Include="HttpHandlers\InProgressItemsHandler.cs" />
|
||||
<Compile Include="HttpHandlers\ItemHandler.cs" />
|
||||
<Compile Include="HttpHandlers\ItemListHandler.cs" />
|
||||
<Compile Include="HttpHandlers\ItemsWithPersonHandler.cs" />
|
||||
<Compile Include="HttpHandlers\JsonHandler.cs" />
|
||||
<Compile Include="HttpHandlers\PersonHandler.cs" />
|
||||
<Compile Include="HttpHandlers\PluginConfigurationHandler.cs" />
|
||||
|
|
|
@ -61,6 +61,10 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
return new ItemsWithYearHandler();
|
||||
}
|
||||
else if (localPath.EndsWith("/api/itemswithperson", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new ItemsWithPersonHandler();
|
||||
}
|
||||
else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new YearsHandler();
|
||||
|
|
|
@ -197,7 +197,7 @@ namespace MediaBrowser.ApiInteraction
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Year
|
||||
/// Gets all items that contain a given Year
|
||||
/// </summary>
|
||||
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithYearAsync(string name, Guid userId)
|
||||
{
|
||||
|
@ -210,7 +210,7 @@ namespace MediaBrowser.ApiInteraction
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Genre
|
||||
/// Gets all items that contain a given Genre
|
||||
/// </summary>
|
||||
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithGenreAsync(string name, Guid userId)
|
||||
{
|
||||
|
@ -222,6 +222,24 @@ namespace MediaBrowser.ApiInteraction
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all items that contain a given Person
|
||||
/// </summary>
|
||||
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/itemswithgenre?userId=" + userId.ToString() + "&name=" + name;
|
||||
|
||||
if (personType.HasValue)
|
||||
{
|
||||
url += "&persontype=" + personType.Value.ToString();
|
||||
}
|
||||
|
||||
using (Stream stream = await HttpClient.GetStreamAsync(url))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>>(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all studious
|
||||
/// </summary>
|
||||
|
@ -249,7 +267,7 @@ namespace MediaBrowser.ApiInteraction
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Studio
|
||||
/// Gets all items that contain a given Studio
|
||||
/// </summary>
|
||||
public async Task<IEnumerable<ApiBaseItemWrapper<ApiBaseItem>>> GetItemsWithStudioAsync(string name, Guid userId)
|
||||
{
|
||||
|
|
|
@ -306,6 +306,29 @@ namespace MediaBrowser.Controller
|
|||
return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.Studios != null && f.Studios.Any(s => s.Equals(studio, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user
|
||||
/// </summary>
|
||||
/// <param name="personType">Specify this to limit results to a specific PersonType</param>
|
||||
public IEnumerable<BaseItem> GetItemsWithPerson(Folder parent, string person, PersonType? personType, Guid userId)
|
||||
{
|
||||
return GetParentalAllowedRecursiveChildren(parent, userId).Where(c =>
|
||||
{
|
||||
if (c.People != null)
|
||||
{
|
||||
if (personType.HasValue)
|
||||
{
|
||||
return c.People.Any(p => p.Name.Equals(person, StringComparison.OrdinalIgnoreCase) && p.PersonType == personType.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return c.People.Any(p => p.Name.Equals(person, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// Finds all recursive items within a top-level parent that contain the given genre and are allowed for the current user
|
||||
/// </summary>
|
||||
|
@ -321,7 +344,7 @@ namespace MediaBrowser.Controller
|
|||
{
|
||||
return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.ProductionYear.HasValue && f.ProductionYear == year);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user
|
||||
/// </summary>
|
||||
|
|
|
@ -3,12 +3,12 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Events;
|
||||
using MediaBrowser.Controller.Events;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
|
||||
namespace MediaBrowser.Controller.Library
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user