mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
added item by name counts
This commit is contained in:
parent
381456f816
commit
e8f345514c
@ -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
|
||||
/// <value>The person types.</value>
|
||||
public string PersonTypes { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Class GetPersonItemCounts
|
||||
/// </summary>
|
||||
[Route("/Users/{UserId}/Persons/{Name}/Counts", "GET")]
|
||||
[Api(Description = "Gets item counts of library items that a person appears in")]
|
||||
public class GetPersonItemCounts : IReturn<ItemByNameCounts>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class PersonsService
|
||||
/// </summary>
|
||||
public class PersonsService : BaseItemsByNameService<Person>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PersonsService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="userManager">The user manager.</param>
|
||||
/// <param name="libraryManager">The library manager.</param>
|
||||
/// <param name="userDataRepository">The user data repository.</param>
|
||||
public PersonsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository)
|
||||
: base(userManager, libraryManager, userDataRepository)
|
||||
{
|
||||
@ -46,6 +76,33 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
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<Movie>().Count(),
|
||||
|
||||
SeriesCount = items.OfType<Series>().Count(),
|
||||
|
||||
GameCount = items.OfType<BaseGame>().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)))
|
||||
};
|
||||
|
||||
return ToOptimizedResult(counts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all items.
|
||||
/// </summary>
|
||||
@ -55,7 +112,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
/// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns>
|
||||
protected override IEnumerable<IbnStub<Person>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> 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();
|
||||
|
35
MediaBrowser.Model/Dto/ItemByNameCounts.cs
Normal file
35
MediaBrowser.Model/Dto/ItemByNameCounts.cs
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
namespace MediaBrowser.Model.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ItemByNameCounts
|
||||
/// </summary>
|
||||
public class ItemByNameCounts
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the total count.
|
||||
/// </summary>
|
||||
/// <value>The total count.</value>
|
||||
public int TotalCount { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the movie count.
|
||||
/// </summary>
|
||||
/// <value>The movie count.</value>
|
||||
public int MovieCount { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the series count.
|
||||
/// </summary>
|
||||
/// <value>The series count.</value>
|
||||
public int SeriesCount { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the episode guest star count.
|
||||
/// </summary>
|
||||
/// <value>The episode guest star count.</value>
|
||||
public int EpisodeGuestStarCount { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the game count.
|
||||
/// </summary>
|
||||
/// <value>The game count.</value>
|
||||
public int GameCount { get; set; }
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@
|
||||
<Compile Include="Dto\BaseItemPerson.cs" />
|
||||
<Compile Include="Dto\ChapterInfoDto.cs" />
|
||||
<Compile Include="Dto\IItemDto.cs" />
|
||||
<Compile Include="Dto\ItemByNameCounts.cs" />
|
||||
<Compile Include="Entities\IByReferenceItem.cs" />
|
||||
<Compile Include="Net\WebSocketMessage.cs" />
|
||||
<Compile Include="Net\WebSocketMessageType.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user