diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs
index fe5cf39f6..52e241318 100644
--- a/MediaBrowser.Api/UserLibrary/PersonsService.cs
+++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs
@@ -1,6 +1,10 @@
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Movies;
+using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.Entities;
using ServiceStack.ServiceHost;
using System;
using System.Collections.Generic;
@@ -23,12 +27,38 @@ namespace MediaBrowser.Api.UserLibrary
/// The person types.
public string PersonTypes { get; set; }
}
-
+
+ ///
+ /// Class GetPersonItemCounts
+ ///
+ [Route("/Users/{UserId}/Persons/{Name}/Counts", "GET")]
+ [Api(Description = "Gets item counts of library items that a person appears in")]
+ public class GetPersonItemCounts : IReturn
+ {
+ ///
+ /// Gets or sets the user id.
+ ///
+ /// The user id.
+ public Guid UserId { get; set; }
+
+ ///
+ /// Gets or sets the name.
+ ///
+ /// The name.
+ public string Name { get; set; }
+ }
+
///
/// Class PersonsService
///
public class PersonsService : BaseItemsByNameService
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The user manager.
+ /// The library manager.
+ /// The user data repository.
public PersonsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository)
: base(userManager, libraryManager, userDataRepository)
{
@@ -46,6 +76,33 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(result);
}
+ ///
+ /// Gets the specified request.
+ ///
+ /// The request.
+ /// System.Object.
+ public object Get(GetPersonItemCounts request)
+ {
+ var user = UserManager.GetUserById(request.UserId);
+
+ var items = user.RootFolder.GetRecursiveChildren(user).Where(i => i.People != null && i.People.Any(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase))).ToList();
+
+ var counts = new ItemByNameCounts
+ {
+ TotalCount = items.Count,
+
+ MovieCount = items.OfType().Count(),
+
+ SeriesCount = items.OfType().Count(),
+
+ GameCount = items.OfType().Count(),
+
+ EpisodeGuestStarCount = items.OfType().Count(i => i.People.Any(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(p.Type, PersonType.GuestStar)))
+ };
+
+ return ToOptimizedResult(counts);
+ }
+
///
/// Gets all items.
///
@@ -55,7 +112,7 @@ namespace MediaBrowser.Api.UserLibrary
/// IEnumerable{Tuple{System.StringFunc{System.Int32}}}.
protected override IEnumerable> GetAllItems(GetItemsByName request, IEnumerable items, User user)
{
- var inputPersonTypes = ((GetPersons) request).PersonTypes;
+ var inputPersonTypes = ((GetPersons)request).PersonTypes;
var personTypes = string.IsNullOrEmpty(inputPersonTypes) ? new string[] { } : inputPersonTypes.Split(',');
var itemsList = items.Where(i => i.People != null).ToList();
diff --git a/MediaBrowser.Model/Dto/ItemByNameCounts.cs b/MediaBrowser.Model/Dto/ItemByNameCounts.cs
new file mode 100644
index 000000000..5175fa158
--- /dev/null
+++ b/MediaBrowser.Model/Dto/ItemByNameCounts.cs
@@ -0,0 +1,35 @@
+
+namespace MediaBrowser.Model.Dto
+{
+ ///
+ /// Class ItemByNameCounts
+ ///
+ public class ItemByNameCounts
+ {
+ ///
+ /// Gets or sets the total count.
+ ///
+ /// The total count.
+ public int TotalCount { get; set; }
+ ///
+ /// Gets or sets the movie count.
+ ///
+ /// The movie count.
+ public int MovieCount { get; set; }
+ ///
+ /// Gets or sets the series count.
+ ///
+ /// The series count.
+ public int SeriesCount { get; set; }
+ ///
+ /// Gets or sets the episode guest star count.
+ ///
+ /// The episode guest star count.
+ public int EpisodeGuestStarCount { get; set; }
+ ///
+ /// Gets or sets the game count.
+ ///
+ /// The game count.
+ public int GameCount { get; set; }
+ }
+}
diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj
index 779fadf11..9df35463c 100644
--- a/MediaBrowser.Model/MediaBrowser.Model.csproj
+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj
@@ -45,6 +45,7 @@
+