diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs
new file mode 100644
index 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
+{
+ ///
+ /// Gets all items within containing a person
+ ///
+ public class ItemsWithPersonHandler : ItemListHandler
+ {
+ protected override IEnumerable 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.csproj
index 0a295fba46..4bd6d89e82 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -55,6 +55,7 @@
+
diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs
index 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.cs
index f8c9170a72..d1c9edf736 100644
--- a/MediaBrowser.ApiInteraction/ApiClient.cs
+++ b/MediaBrowser.ApiInteraction/ApiClient.cs
@@ -197,7 +197,7 @@ namespace MediaBrowser.ApiInteraction
}
///
- /// Gets a Year
+ /// Gets all items that contain a given Year
///
public async Task>> GetItemsWithYearAsync(string name, Guid userId)
{
@@ -210,7 +210,7 @@ namespace MediaBrowser.ApiInteraction
}
///
- /// Gets a Genre
+ /// Gets all items that contain a given Genre
///
public async Task>> GetItemsWithGenreAsync(string name, Guid userId)
{
@@ -222,6 +222,24 @@ namespace MediaBrowser.ApiInteraction
}
}
+ ///
+ /// Gets all items that contain a given Person
+ ///
+ public async Task>> 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>>(stream);
+ }
+ }
+
///
/// Gets all studious
///
@@ -249,7 +267,7 @@ namespace MediaBrowser.ApiInteraction
}
///
- /// Gets a Studio
+ /// Gets all items that contain a given Studio
///
public async Task>> GetItemsWithStudioAsync(string name, Guid userId)
{
diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs
index a8baec8351..18598d0144 100644
--- a/MediaBrowser.Controller/Kernel.cs
+++ b/MediaBrowser.Controller/Kernel.cs
@@ -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)));
}
+ ///
+ /// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user
+ ///
+ /// Specify this to limit results to a specific PersonType
+ public IEnumerable 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;
+ });
+ }
///
/// Finds all recursive items within a top-level parent that contain the given genre and are allowed for the current user
///
@@ -321,7 +344,7 @@ namespace MediaBrowser.Controller
{
return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.ProductionYear.HasValue && f.ProductionYear == year);
}
-
+
///
/// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user
///
diff --git a/MediaBrowser.Controller/Library/ItemController.cs b/MediaBrowser.Controller/Library/ItemController.cs
index 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
{