added count api methods for studios and genres

pull/702/head
Luke Pulverenti 12 years ago
parent a5e2778f62
commit d59df69b5b

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

@ -1,6 +1,11 @@
using MediaBrowser.Controller.Entities; 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.Library;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -19,6 +24,28 @@ namespace MediaBrowser.Api.UserLibrary
{ {
} }
/// <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> /// <summary>
/// Class GenresService /// Class GenresService
/// </summary> /// </summary>
@ -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> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>

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

@ -1,6 +1,10 @@
using MediaBrowser.Controller.Entities; 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.Library;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -19,6 +23,25 @@ namespace MediaBrowser.Api.UserLibrary
{ {
} }
[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> /// <summary>
/// Class StudiosService /// Class StudiosService
/// </summary> /// </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> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>

@ -31,5 +31,20 @@ namespace MediaBrowser.Model.Dto
/// </summary> /// </summary>
/// <value>The game count.</value> /// <value>The game count.</value>
public int GameCount { get; set; } 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; }
} }
} }

Loading…
Cancel
Save