2013-08-09 17:55:22 +02:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2014-03-30 18:49:40 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-07-02 20:34:08 +02:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2014-12-13 04:56:30 +01:00
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2016-06-19 08:18:29 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-08-19 21:43:35 +02:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2016-10-25 21:02:04 +02:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2017-08-09 21:56:38 +02:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2014-03-06 06:17:13 +01:00
|
|
|
|
namespace MediaBrowser.Api.Music
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/Songs/{Id}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given song")]
|
2013-08-09 17:55:22 +02:00
|
|
|
|
public class GetInstantMixFromSong : BaseGetSimilarItemsFromItem
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/Albums/{Id}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given album")]
|
2013-08-09 17:55:22 +02:00
|
|
|
|
public class GetInstantMixFromAlbum : BaseGetSimilarItemsFromItem
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-13 04:56:30 +01:00
|
|
|
|
[Route("/Playlists/{Id}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given playlist")]
|
|
|
|
|
public class GetInstantMixFromPlaylist : BaseGetSimilarItemsFromItem
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/Artists/{Name}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given artist")]
|
2013-08-09 17:55:22 +02:00
|
|
|
|
public class GetInstantMixFromArtist : BaseGetSimilarItems
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Name", Description = "The artist name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/MusicGenres/{Name}/InstantMix", "GET", Summary = "Creates an instant playlist based on a music genre")]
|
2013-08-09 17:55:22 +02:00
|
|
|
|
public class GetInstantMixFromMusicGenre : BaseGetSimilarItems
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Name", Description = "The genre name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-18 16:20:02 +02:00
|
|
|
|
[Route("/Artists/InstantMix", "GET", Summary = "Creates an instant playlist based on a given artist")]
|
|
|
|
|
public class GetInstantMixFromArtistId : BaseGetSimilarItems
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Id", Description = "The artist Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/MusicGenres/InstantMix", "GET", Summary = "Creates an instant playlist based on a music genre")]
|
|
|
|
|
public class GetInstantMixFromMusicGenreId : BaseGetSimilarItems
|
|
|
|
|
{
|
2015-05-25 21:08:05 +02:00
|
|
|
|
[ApiMember(Name = "Id", Description = "The genre Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2014-08-18 16:20:02 +02:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 06:19:08 +02:00
|
|
|
|
[Route("/Items/{Id}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given item")]
|
|
|
|
|
public class GetInstantMixFromItem : BaseGetSimilarItemsFromItem
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-02 20:34:08 +02:00
|
|
|
|
[Authenticated]
|
2013-08-09 17:55:22 +02:00
|
|
|
|
public class InstantMixService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
private readonly IDtoService _dtoService;
|
2014-04-25 22:15:50 +02:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-03-30 18:49:40 +02:00
|
|
|
|
private readonly IMusicManager _musicManager;
|
2016-11-10 15:41:24 +01:00
|
|
|
|
private readonly IAuthorizationContext _authContext;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2016-11-10 15:41:24 +01:00
|
|
|
|
public InstantMixService(IUserManager userManager, IDtoService dtoService, IMusicManager musicManager, ILibraryManager libraryManager, IAuthorizationContext authContext)
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
|
|
|
|
_userManager = userManager;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
_dtoService = dtoService;
|
2014-03-30 18:49:40 +02:00
|
|
|
|
_musicManager = musicManager;
|
2014-04-25 22:15:50 +02:00
|
|
|
|
_libraryManager = libraryManager;
|
2016-11-10 15:41:24 +01:00
|
|
|
|
_authContext = authContext;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromItem request)
|
2015-08-28 06:19:08 +02:00
|
|
|
|
{
|
|
|
|
|
var item = _libraryManager.GetItemById(request.Id);
|
|
|
|
|
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
|
|
|
|
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
2015-08-28 06:19:08 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2015-08-28 06:19:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromArtistId request)
|
2014-08-18 16:20:02 +02:00
|
|
|
|
{
|
2015-01-26 17:47:15 +01:00
|
|
|
|
var item = _libraryManager.GetItemById(request.Id);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
|
|
|
|
|
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromMusicGenreId request)
|
2014-08-18 16:20:02 +02:00
|
|
|
|
{
|
2015-01-26 17:47:15 +01:00
|
|
|
|
var item = _libraryManager.GetItemById(request.Id);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
|
|
|
|
|
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2014-08-18 16:20:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromSong request)
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2015-01-26 17:47:15 +01:00
|
|
|
|
var item = _libraryManager.GetItemById(request.Id);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
|
|
|
|
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
2014-03-30 18:49:40 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromAlbum request)
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2015-01-26 17:47:15 +01:00
|
|
|
|
var album = _libraryManager.GetItemById(request.Id);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-08-09 18:33:12 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
|
|
|
|
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(album, user, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromPlaylist request)
|
2014-12-13 04:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
var playlist = (Playlist)_libraryManager.GetItemById(request.Id);
|
|
|
|
|
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2014-12-13 04:56:30 +01:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
|
|
|
|
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(playlist, user, dtoOptions);
|
2014-12-13 04:56:30 +01:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2014-12-13 04:56:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromMusicGenre request)
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
|
|
|
|
|
|
|
|
var items = _musicManager.GetInstantMixFromGenres(new[] { request.Name }, user, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
public object Get(GetInstantMixFromArtist request)
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2015-05-30 01:51:33 +02:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2017-05-22 06:54:02 +02:00
|
|
|
|
var artist = _libraryManager.GetArtist(request.Name, new DtoOptions(false));
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
var dtoOptions = GetDtoOptions(_authContext, request);
|
|
|
|
|
|
|
|
|
|
var items = _musicManager.GetInstantMixFromArtist(artist, user, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-05-21 09:25:49 +02:00
|
|
|
|
return GetResult(items, user, request, dtoOptions);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
private object GetResult(List<BaseItem> items, User user, BaseGetSimilarItems request, DtoOptions dtoOptions)
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2017-08-09 21:56:38 +02:00
|
|
|
|
var list = items;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2017-08-19 21:43:35 +02:00
|
|
|
|
var result = new QueryResult<BaseItemDto>
|
2013-08-09 17:55:22 +02:00
|
|
|
|
{
|
2014-03-30 18:49:40 +02:00
|
|
|
|
TotalRecordCount = list.Count
|
2013-08-09 17:55:22 +02:00
|
|
|
|
};
|
|
|
|
|
|
2017-08-19 21:43:35 +02:00
|
|
|
|
if (request.Limit.HasValue)
|
|
|
|
|
{
|
|
|
|
|
list = list.Take(request.Limit.Value).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 02:33:05 +02:00
|
|
|
|
var returnList = _dtoService.GetBaseItemDtos(list, dtoOptions, user);
|
2017-08-09 21:56:38 +02:00
|
|
|
|
|
2017-08-19 21:43:35 +02:00
|
|
|
|
result.Items = returnList;
|
2013-08-09 17:55:22 +02:00
|
|
|
|
|
2014-03-30 18:49:40 +02:00
|
|
|
|
return ToOptimizedResult(result);
|
2013-08-09 17:55:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|