The Free Software Media System - Server Backend & API
Added GetItemsWithPerson
LukePulverenti Luke Pulverenti luke pulverenti0788f435c185
diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.csnew file mode 100644index 0000000000..624abc7620--- /dev/null+++ b/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs@@ -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);+ }+ }+ }+}diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csprojindex 0a295fba46..4bd6d89e82 100644--- a/MediaBrowser.Api/MediaBrowser.Api.csproj+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj@@ -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" />diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.csindex efbd9725eb..92127f98cc 100644--- a/MediaBrowser.Api/Plugin.cs+++ b/MediaBrowser.Api/Plugin.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();diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.csindex f8c9170a72..d1c9edf736 100644--- a/MediaBrowser.ApiInteraction/ApiClient.cs+++ b/MediaBrowser.ApiInteraction/ApiClient.cs@@ -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){diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.csindex a8baec8351..18598d0144 100644--- a/MediaBrowser.Controller/Kernel.cs+++ b/MediaBrowser.Controller/Kernel.cs@@ -306,6 +306,29 @@ namespace MediaBrowser.Controllerreturn 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>diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.csindex 0c62ce7d9a..10648eca09 100644--- a/MediaBrowser.Controller/Library/ItemController.cs+++ b/MediaBrowser.Controller/Library/ItemController.cs@@ -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{