From d59df69b5bd3a55099c356b2a34f3630ef9b8f00 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 17 Apr 2013 10:42:25 -0400 Subject: added count api methods for studios and genres --- MediaBrowser.Api/UserLibrary/StudiosService.cs | 56 +++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Api/UserLibrary/StudiosService.cs') diff --git a/MediaBrowser.Api/UserLibrary/StudiosService.cs b/MediaBrowser.Api/UserLibrary/StudiosService.cs index e2c1c4743..4072311d7 100644 --- a/MediaBrowser.Api/UserLibrary/StudiosService.cs +++ b/MediaBrowser.Api/UserLibrary/StudiosService.cs @@ -1,6 +1,10 @@ using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Dto; using ServiceStack.ServiceHost; using System; using System.Collections.Generic; @@ -18,7 +22,26 @@ namespace MediaBrowser.Api.UserLibrary public class GetStudios : GetItemsByName { } - + + [Route("/Users/{UserId}/Studios/{Name}/Counts", "GET")] + [Api(Description = "Gets item counts of library items that a studio appears in")] + public class GetStudioItemCounts : IReturn + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "The studio name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Name { get; set; } + } + /// /// Class StudiosService /// @@ -29,6 +52,37 @@ namespace MediaBrowser.Api.UserLibrary { } + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetStudioItemCounts request) + { + var user = UserManager.GetUserById(request.UserId); + + var items = user.RootFolder.GetRecursiveChildren(user).Where(i => i.Studios != null && i.Studios.Contains(request.Name, StringComparer.OrdinalIgnoreCase)).ToList(); + + var counts = new ItemByNameCounts + { + TotalCount = items.Count, + + TrailerCount = items.OfType().Count(), + + MovieCount = items.OfType().Count(), + + SeriesCount = items.OfType().Count(), + + GameCount = items.OfType().Count(), + + SongCount = items.OfType().Count(), + + AlbumCount = items.OfType().Count() + }; + + return ToOptimizedResult(counts); + } + /// /// Gets the specified request. /// -- cgit v1.2.3