diff options
| -rw-r--r-- | MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs | 32 | ||||
| -rw-r--r-- | MediaBrowser.Api/MediaBrowser.Api.csproj | 1 | ||||
| -rw-r--r-- | MediaBrowser.Api/Plugin.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.ApiInteraction/ApiClient.cs | 24 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Kernel.cs | 25 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Library/ItemController.cs | 2 |
6 files changed, 83 insertions, 5 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs new file mode 100644 index 000000000..624abc762 --- /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.csproj index 0a295fba4..4bd6d89e8 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.cs index efbd9725e..92127f98c 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 f8c9170a7..d1c9edf73 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)
{
@@ -223,6 +223,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>
public async Task<IEnumerable<CategoryInfo<Studio>>> GetAllStudiosAsync(Guid userId)
@@ -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.cs index a8baec835..18598d014 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -307,6 +307,29 @@ namespace MediaBrowser.Controller }
/// <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>
public IEnumerable<BaseItem> GetItemsWithGenre(Folder parent, string genre, Guid userId)
@@ -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.cs index 0c62ce7d9..10648eca0 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
{
|
