You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Api/UserLibrary/ArtistsService.cs

141 lines
4.8 KiB

12 years ago
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
12 years ago
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto;
using ServiceStack;
12 years ago
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.UserLibrary
{
/// <summary>
/// Class GetArtists
/// </summary>
[Route("/Artists", "GET", Summary = "Gets all artists from a given item, folder, or the entire library")]
12 years ago
public class GetArtists : GetItemsByName
{
}
[Route("/Artists/AlbumArtists", "GET", Summary = "Gets all album artists from a given item, folder, or the entire library")]
public class GetAlbumArtists : GetItemsByName
{
}
[Route("/Artists/{Name}", "GET", Summary = "Gets an artist, by name")]
12 years ago
public class GetArtist : IReturn<BaseItemDto>
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "Name", Description = "The artist name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "Optional. Filter by user id, and attach user data", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get; set; }
12 years ago
}
/// <summary>
/// Class ArtistsService
/// </summary>
[Authenticated]
public class ArtistsService : BaseItemsByNameService<MusicArtist>
12 years ago
{
/// <summary>
/// Initializes a new instance of the <see cref="ArtistsService" /> class.
12 years ago
/// </summary>
/// <param name="userManager">The user manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userDataRepository">The user data repository.</param>
/// <param name="itemRepo">The item repo.</param>
public ArtistsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IDtoService dtoService)
11 years ago
: base(userManager, libraryManager, userDataRepository, itemRepo, dtoService)
12 years ago
{
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetArtist request)
{
var result = GetItem(request);
12 years ago
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the item.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Task{BaseItemDto}.</returns>
private BaseItemDto GetItem(GetArtist request)
12 years ago
{
var item = GetArtist(request.Name, LibraryManager);
12 years ago
10 years ago
var dtoOptions = GetDtoOptions(request);
12 years ago
if (!string.IsNullOrWhiteSpace(request.UserId))
12 years ago
{
var user = UserManager.GetUserById(request.UserId);
return DtoService.GetBaseItemDto(item, dtoOptions, user);
12 years ago
}
return DtoService.GetBaseItemDto(item, dtoOptions);
12 years ago
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetArtists request)
{
var result = GetResult(request);
12 years ago
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetAlbumArtists request)
{
var result = GetResult(request);
return ToOptimizedResult(result);
}
12 years ago
/// <summary>
/// Gets all items.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="items">The items.</param>
/// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns>
protected override IEnumerable<BaseItem> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items)
12 years ago
{
if (request is GetAlbumArtists)
{
9 years ago
return LibraryManager.GetAlbumArtists(items
.Where(i => !i.IsFolder)
.OfType<IHasAlbumArtist>());
}
9 years ago
return LibraryManager.GetArtists(items
.Where(i => !i.IsFolder)
9 years ago
.OfType<IHasArtist>());
12 years ago
}
}
}