ソースを参照

added count api methods for studios and genres

Luke Pulverenti 12 年 前
コミット
d59df69b5b

+ 4 - 0
MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs

@@ -1,8 +1,12 @@
 using MediaBrowser.Controller.Dto;
 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 MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Querying;
 using ServiceStack.ServiceHost;
 using System;

+ 58 - 0
MediaBrowser.Api/UserLibrary/GenresService.cs

@@ -1,6 +1,11 @@
 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 MediaBrowser.Model.Entities;
 using ServiceStack.ServiceHost;
 using System;
 using System.Collections.Generic;
@@ -18,6 +23,28 @@ namespace MediaBrowser.Api.UserLibrary
     public class GetGenres : GetItemsByName
     {
     }
+
+    /// <summary>
+    /// Class GetGenreItemCounts
+    /// </summary>
+    [Route("/Users/{UserId}/Genres/{Name}/Counts", "GET")]
+    [Api(Description = "Gets item counts of library items that a genre appears in")]
+    public class GetGenreItemCounts : IReturn<ItemByNameCounts>
+    {
+        /// <summary>
+        /// Gets or sets the user id.
+        /// </summary>
+        /// <value>The user id.</value>
+        [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+        public Guid UserId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        [ApiMember(Name = "Name", Description = "The genre name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+        public string Name { get; set; }
+    }
     
     /// <summary>
     /// Class GenresService
@@ -29,6 +56,37 @@ namespace MediaBrowser.Api.UserLibrary
         {
         }
 
+        /// <summary>
+        /// Gets the specified request.
+        /// </summary>
+        /// <param name="request">The request.</param>
+        /// <returns>System.Object.</returns>
+        public object Get(GetGenreItemCounts request)
+        {
+            var user = UserManager.GetUserById(request.UserId);
+
+            var items = user.RootFolder.GetRecursiveChildren(user).Where(i => i.Genres != null && i.Genres.Contains(request.Name, StringComparer.OrdinalIgnoreCase)).ToList();
+
+            var counts = new ItemByNameCounts
+            {
+                TotalCount = items.Count,
+
+                TrailerCount = items.OfType<Trailer>().Count(),
+
+                MovieCount = items.OfType<Movie>().Count(),
+
+                SeriesCount = items.OfType<Series>().Count(),
+
+                GameCount = items.OfType<BaseGame>().Count(),
+
+                SongCount = items.OfType<AudioCodecs>().Count(),
+
+                AlbumCount = items.OfType<MusicAlbum>().Count()
+            };
+
+            return ToOptimizedResult(counts);
+        }
+        
         /// <summary>
         /// Gets the specified request.
         /// </summary>

+ 9 - 0
MediaBrowser.Api/UserLibrary/PersonsService.cs

@@ -1,4 +1,5 @@
 using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
 using MediaBrowser.Controller.Entities.Movies;
 using MediaBrowser.Controller.Entities.TV;
 using MediaBrowser.Controller.Library;
@@ -39,12 +40,14 @@ namespace MediaBrowser.Api.UserLibrary
         /// Gets or sets the user id.
         /// </summary>
         /// <value>The user id.</value>
+        [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
         public Guid UserId { get; set; }
 
         /// <summary>
         /// Gets or sets the name.
         /// </summary>
         /// <value>The name.</value>
+        [ApiMember(Name = "Name", Description = "The person name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
         public string Name { get; set; }
     }
 
@@ -91,12 +94,18 @@ namespace MediaBrowser.Api.UserLibrary
             {
                 TotalCount = items.Count,
 
+                TrailerCount = items.OfType<Trailer>().Count(),
+
                 MovieCount = items.OfType<Movie>().Count(),
 
                 SeriesCount = items.OfType<Series>().Count(),
 
                 GameCount = items.OfType<BaseGame>().Count(),
 
+                SongCount = items.OfType<AudioCodecs>().Count(),
+
+                AlbumCount = items.OfType<MusicAlbum>().Count(),
+
                 EpisodeGuestStarCount = items.OfType<Episode>().Count(i => i.People.Any(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(p.Type, PersonType.GuestStar)))
             };
 

+ 55 - 1
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<ItemByNameCounts>
+    {
+        /// <summary>
+        /// Gets or sets the user id.
+        /// </summary>
+        /// <value>The user id.</value>
+        [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+        public Guid UserId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        [ApiMember(Name = "Name", Description = "The studio name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+        public string Name { get; set; }
+    }
+
     /// <summary>
     /// Class StudiosService
     /// </summary>
@@ -29,6 +52,37 @@ namespace MediaBrowser.Api.UserLibrary
         {
         }
 
+        /// <summary>
+        /// Gets the specified request.
+        /// </summary>
+        /// <param name="request">The request.</param>
+        /// <returns>System.Object.</returns>
+        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<Trailer>().Count(),
+
+                MovieCount = items.OfType<Movie>().Count(),
+
+                SeriesCount = items.OfType<Series>().Count(),
+
+                GameCount = items.OfType<BaseGame>().Count(),
+
+                SongCount = items.OfType<AudioCodecs>().Count(),
+
+                AlbumCount = items.OfType<MusicAlbum>().Count()
+            };
+
+            return ToOptimizedResult(counts);
+        }
+
         /// <summary>
         /// Gets the specified request.
         /// </summary>

+ 15 - 0
MediaBrowser.Model/Dto/ItemByNameCounts.cs

@@ -31,5 +31,20 @@ namespace MediaBrowser.Model.Dto
         /// </summary>
         /// <value>The game count.</value>
         public int GameCount { get; set; }
+        /// <summary>
+        /// Gets or sets the trailer count.
+        /// </summary>
+        /// <value>The trailer count.</value>
+        public int TrailerCount { get; set; }
+        /// <summary>
+        /// Gets or sets the song count.
+        /// </summary>
+        /// <value>The song count.</value>
+        public int SongCount { get; set; }
+        /// <summary>
+        /// Gets or sets the album count.
+        /// </summary>
+        /// <value>The album count.</value>
+        public int AlbumCount { get; set; }
     }
 }