2020-11-21 14:26:03 +01:00
|
|
|
using System;
|
2020-06-26 13:42:21 +02:00
|
|
|
using System.Collections.Generic;
|
2020-08-06 16:17:45 +02:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-06-26 13:42:21 +02:00
|
|
|
using Jellyfin.Api.Extensions;
|
2023-02-17 23:16:08 +01:00
|
|
|
using Jellyfin.Api.Helpers;
|
2020-11-09 22:59:04 +01:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2020-06-26 13:42:21 +02:00
|
|
|
using Jellyfin.Data.Entities;
|
2024-01-17 16:51:39 +01:00
|
|
|
using Jellyfin.Extensions;
|
2020-06-26 13:42:21 +02:00
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
|
|
|
using MediaBrowser.Model.Dto;
|
2020-10-10 01:52:39 +02:00
|
|
|
using MediaBrowser.Model.Entities;
|
2020-06-26 13:42:21 +02:00
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-26 17:45:07 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-06-26 13:42:21 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
namespace Jellyfin.Api.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The instant mix controller.
|
|
|
|
/// </summary>
|
|
|
|
[Route("")]
|
2023-02-08 23:55:26 +01:00
|
|
|
[Authorize]
|
2023-01-31 12:18:10 +01:00
|
|
|
public class InstantMixController : BaseJellyfinApiController
|
2020-06-26 13:42:21 +02:00
|
|
|
{
|
2023-01-31 12:18:10 +01:00
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
private readonly IMusicManager _musicManager;
|
|
|
|
|
2020-06-26 13:42:21 +02:00
|
|
|
/// <summary>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// Initializes a new instance of the <see cref="InstantMixController"/> class.
|
2020-06-26 13:42:21 +02:00
|
|
|
/// </summary>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|
|
|
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
|
|
|
|
/// <param name="musicManager">Instance of the <see cref="IMusicManager"/> interface.</param>
|
|
|
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
|
|
public InstantMixController(
|
|
|
|
IUserManager userManager,
|
|
|
|
IDtoService dtoService,
|
|
|
|
IMusicManager musicManager,
|
|
|
|
ILibraryManager libraryManager)
|
2020-06-26 13:42:21 +02:00
|
|
|
{
|
2023-01-31 12:18:10 +01:00
|
|
|
_userManager = userManager;
|
|
|
|
_dtoService = dtoService;
|
|
|
|
_musicManager = musicManager;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given song.
|
|
|
|
/// </summary>
|
2024-02-26 23:57:59 +01:00
|
|
|
/// <param name="itemId">The item id.</param>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
2024-02-26 23:57:59 +01:00
|
|
|
[HttpGet("Songs/{itemId}/InstantMix")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromSong(
|
2024-02-26 23:57:59 +01:00
|
|
|
[FromRoute, Required] Guid itemId,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
2024-04-14 16:18:36 +02:00
|
|
|
var item = _libraryManager.GetItemById<BaseItem>(itemId, user);
|
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given album.
|
|
|
|
/// </summary>
|
2024-02-26 23:57:59 +01:00
|
|
|
/// <param name="itemId">The item id.</param>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
2024-02-26 23:57:59 +01:00
|
|
|
[HttpGet("Albums/{itemId}/InstantMix")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromAlbum(
|
2024-02-26 23:57:59 +01:00
|
|
|
[FromRoute, Required] Guid itemId,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
2024-04-14 16:18:36 +02:00
|
|
|
var item = _libraryManager.GetItemById<BaseItem>(itemId, user);
|
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
2024-04-14 16:18:36 +02:00
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
2023-01-31 12:18:10 +01:00
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given playlist.
|
|
|
|
/// </summary>
|
2024-02-26 23:57:59 +01:00
|
|
|
/// <param name="itemId">The item id.</param>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
2024-02-26 23:57:59 +01:00
|
|
|
[HttpGet("Playlists/{itemId}/InstantMix")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromPlaylist(
|
2024-02-26 23:57:59 +01:00
|
|
|
[FromRoute, Required] Guid itemId,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
2024-04-14 16:18:36 +02:00
|
|
|
var item = _libraryManager.GetItemById<Playlist>(itemId, user);
|
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
2024-04-14 16:18:36 +02:00
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
2023-01-31 12:18:10 +01:00
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given genre.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The genre name.</param>
|
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
|
|
|
[HttpGet("MusicGenres/{name}/InstantMix")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromMusicGenreByName(
|
|
|
|
[FromRoute, Required] string name,
|
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
|
|
|
var items = _musicManager.GetInstantMixFromGenres(new[] { name }, user, dtoOptions);
|
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given artist.
|
|
|
|
/// </summary>
|
2024-02-26 23:57:59 +01:00
|
|
|
/// <param name="itemId">The item id.</param>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
2024-02-26 23:57:59 +01:00
|
|
|
[HttpGet("Artists/{itemId}/InstantMix")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromArtists(
|
2024-02-26 23:57:59 +01:00
|
|
|
[FromRoute, Required] Guid itemId,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
2024-04-14 16:18:36 +02:00
|
|
|
var item = _libraryManager.GetItemById<BaseItem>(itemId, user);
|
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given item.
|
|
|
|
/// </summary>
|
2024-02-26 23:57:59 +01:00
|
|
|
/// <param name="itemId">The item id.</param>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
2024-02-26 23:57:59 +01:00
|
|
|
[HttpGet("Items/{itemId}/InstantMix")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromItem(
|
2024-02-26 23:57:59 +01:00
|
|
|
[FromRoute, Required] Guid itemId,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
2024-04-14 16:18:36 +02:00
|
|
|
var item = _libraryManager.GetItemById<BaseItem>(itemId, user);
|
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given artist.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">The item id.</param>
|
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
|
|
|
[HttpGet("Artists/InstantMix")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
[Obsolete("Use GetInstantMixFromArtists")]
|
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromArtists2(
|
|
|
|
[FromQuery, Required] Guid id,
|
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
|
|
|
return GetInstantMixFromArtists(
|
|
|
|
id,
|
|
|
|
userId,
|
|
|
|
limit,
|
|
|
|
fields,
|
|
|
|
enableImages,
|
|
|
|
enableUserData,
|
|
|
|
imageTypeLimit,
|
|
|
|
enableImageTypes);
|
|
|
|
}
|
2021-03-13 17:09:22 +01:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates an instant playlist based on a given genre.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">The item id.</param>
|
|
|
|
/// <param name="userId">Optional. Filter by user id, and attach user data.</param>
|
|
|
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
|
|
|
/// <param name="enableImages">Optional. Include image information in output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. Include user data.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <response code="200">Instant playlist returned.</response>
|
2024-04-14 16:18:36 +02:00
|
|
|
/// <response code="404">Item not found.</response>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns>
|
|
|
|
[HttpGet("MusicGenres/InstantMix")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-04-14 16:18:36 +02:00
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-01-31 12:18:10 +01:00
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromMusicGenreById(
|
|
|
|
[FromQuery, Required] Guid id,
|
|
|
|
[FromQuery] Guid? userId,
|
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
|
|
|
{
|
2023-02-17 23:16:08 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
2024-01-17 16:51:39 +01:00
|
|
|
var user = userId.IsNullOrEmpty()
|
2023-01-31 12:18:10 +01:00
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId.Value);
|
2024-04-14 16:18:36 +02:00
|
|
|
var item = _libraryManager.GetItemById<BaseItem>(id, user);
|
|
|
|
if (item is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
|
|
|
.AddClientFields(User)
|
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
|
|
|
var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions);
|
|
|
|
return GetResult(items, user, limit, dtoOptions);
|
|
|
|
}
|
2021-03-13 17:09:22 +01:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
private QueryResult<BaseItemDto> GetResult(List<BaseItem> items, User? user, int? limit, DtoOptions dtoOptions)
|
|
|
|
{
|
|
|
|
var list = items;
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var totalCount = list.Count;
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
if (limit.HasValue && limit < list.Count)
|
|
|
|
{
|
|
|
|
list = list.GetRange(0, limit.Value);
|
|
|
|
}
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var returnList = _dtoService.GetBaseItemDtos(list, dtoOptions, user);
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var result = new QueryResult<BaseItemDto>(
|
|
|
|
0,
|
|
|
|
totalCount,
|
|
|
|
returnList);
|
2020-06-26 13:42:21 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
return result;
|
2020-06-26 13:42:21 +02:00
|
|
|
}
|
|
|
|
}
|