| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Collections.Immutable; |
| | | 4 | | using System.ComponentModel.DataAnnotations; |
| | | 5 | | using System.Linq; |
| | | 6 | | using Jellyfin.Api.Extensions; |
| | | 7 | | using Jellyfin.Api.Helpers; |
| | | 8 | | using Jellyfin.Api.ModelBinders; |
| | | 9 | | using Jellyfin.Database.Implementations.Entities; |
| | | 10 | | using Jellyfin.Extensions; |
| | | 11 | | using MediaBrowser.Controller.Dto; |
| | | 12 | | using MediaBrowser.Controller.Entities; |
| | | 13 | | using MediaBrowser.Controller.Library; |
| | | 14 | | using MediaBrowser.Controller.Playlists; |
| | | 15 | | using MediaBrowser.Model.Dto; |
| | | 16 | | using MediaBrowser.Model.Entities; |
| | | 17 | | using MediaBrowser.Model.Querying; |
| | | 18 | | using Microsoft.AspNetCore.Authorization; |
| | | 19 | | using Microsoft.AspNetCore.Http; |
| | | 20 | | using Microsoft.AspNetCore.Mvc; |
| | | 21 | | |
| | | 22 | | namespace Jellyfin.Api.Controllers; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// The instant mix controller. |
| | | 26 | | /// </summary> |
| | | 27 | | [Route("")] |
| | | 28 | | [Authorize] |
| | | 29 | | public class InstantMixController : BaseJellyfinApiController |
| | | 30 | | { |
| | | 31 | | private readonly IUserManager _userManager; |
| | | 32 | | private readonly IDtoService _dtoService; |
| | | 33 | | private readonly ILibraryManager _libraryManager; |
| | | 34 | | private readonly IMusicManager _musicManager; |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Initializes a new instance of the <see cref="InstantMixController"/> class. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param> |
| | | 40 | | /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param> |
| | | 41 | | /// <param name="musicManager">Instance of the <see cref="IMusicManager"/> interface.</param> |
| | | 42 | | /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> |
| | 0 | 43 | | public InstantMixController( |
| | 0 | 44 | | IUserManager userManager, |
| | 0 | 45 | | IDtoService dtoService, |
| | 0 | 46 | | IMusicManager musicManager, |
| | 0 | 47 | | ILibraryManager libraryManager) |
| | | 48 | | { |
| | 0 | 49 | | _userManager = userManager; |
| | 0 | 50 | | _dtoService = dtoService; |
| | 0 | 51 | | _musicManager = musicManager; |
| | 0 | 52 | | _libraryManager = libraryManager; |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Creates an instant playlist based on a given song. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <param name="itemId">The item id.</param> |
| | | 59 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 60 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 61 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 62 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 63 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 64 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 65 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 66 | | /// <response code="200">Instant playlist returned.</response> |
| | | 67 | | /// <response code="404">Item not found.</response> |
| | | 68 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 69 | | [HttpGet("Songs/{itemId}/InstantMix")] |
| | | 70 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 71 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 72 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromSong( |
| | | 73 | | [FromRoute, Required] Guid itemId, |
| | | 74 | | [FromQuery] Guid? userId, |
| | | 75 | | [FromQuery] int? limit, |
| | | 76 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 77 | | [FromQuery] bool? enableImages, |
| | | 78 | | [FromQuery] bool? enableUserData, |
| | | 79 | | [FromQuery] int? imageTypeLimit, |
| | | 80 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 81 | | { |
| | 0 | 82 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 83 | | var user = userId.IsNullOrEmpty() |
| | 0 | 84 | | ? null |
| | 0 | 85 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 86 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 0 | 87 | | if (item is null) |
| | | 88 | | { |
| | 0 | 89 | | return NotFound(); |
| | | 90 | | } |
| | | 91 | | |
| | 0 | 92 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 93 | | .AddClientFields(User) |
| | 0 | 94 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 95 | | var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions); |
| | 0 | 96 | | return GetResult(items, user, limit, dtoOptions); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// Creates an instant playlist based on a given album. |
| | | 101 | | /// </summary> |
| | | 102 | | /// <param name="itemId">The item id.</param> |
| | | 103 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 104 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 105 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 106 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 107 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 108 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 109 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 110 | | /// <response code="200">Instant playlist returned.</response> |
| | | 111 | | /// <response code="404">Item not found.</response> |
| | | 112 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 113 | | [HttpGet("Albums/{itemId}/InstantMix")] |
| | | 114 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 115 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 116 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromAlbum( |
| | | 117 | | [FromRoute, Required] Guid itemId, |
| | | 118 | | [FromQuery] Guid? userId, |
| | | 119 | | [FromQuery] int? limit, |
| | | 120 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 121 | | [FromQuery] bool? enableImages, |
| | | 122 | | [FromQuery] bool? enableUserData, |
| | | 123 | | [FromQuery] int? imageTypeLimit, |
| | | 124 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 125 | | { |
| | 0 | 126 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 127 | | var user = userId.IsNullOrEmpty() |
| | 0 | 128 | | ? null |
| | 0 | 129 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 130 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 0 | 131 | | if (item is null) |
| | | 132 | | { |
| | 0 | 133 | | return NotFound(); |
| | | 134 | | } |
| | | 135 | | |
| | 0 | 136 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 137 | | .AddClientFields(User) |
| | 0 | 138 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 139 | | var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions); |
| | 0 | 140 | | return GetResult(items, user, limit, dtoOptions); |
| | | 141 | | } |
| | | 142 | | |
| | | 143 | | /// <summary> |
| | | 144 | | /// Creates an instant playlist based on a given playlist. |
| | | 145 | | /// </summary> |
| | | 146 | | /// <param name="itemId">The item id.</param> |
| | | 147 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 148 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 149 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 150 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 151 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 152 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 153 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 154 | | /// <response code="200">Instant playlist returned.</response> |
| | | 155 | | /// <response code="404">Item not found.</response> |
| | | 156 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 157 | | [HttpGet("Playlists/{itemId}/InstantMix")] |
| | | 158 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 159 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 160 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromPlaylist( |
| | | 161 | | [FromRoute, Required] Guid itemId, |
| | | 162 | | [FromQuery] Guid? userId, |
| | | 163 | | [FromQuery] int? limit, |
| | | 164 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 165 | | [FromQuery] bool? enableImages, |
| | | 166 | | [FromQuery] bool? enableUserData, |
| | | 167 | | [FromQuery] int? imageTypeLimit, |
| | | 168 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 169 | | { |
| | 0 | 170 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 171 | | var user = userId.IsNullOrEmpty() |
| | 0 | 172 | | ? null |
| | 0 | 173 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 174 | | var item = _libraryManager.GetItemById<Playlist>(itemId, user); |
| | 0 | 175 | | if (item is null) |
| | | 176 | | { |
| | 0 | 177 | | return NotFound(); |
| | | 178 | | } |
| | | 179 | | |
| | 0 | 180 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 181 | | .AddClientFields(User) |
| | 0 | 182 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 183 | | var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions); |
| | 0 | 184 | | return GetResult(items, user, limit, dtoOptions); |
| | | 185 | | } |
| | | 186 | | |
| | | 187 | | /// <summary> |
| | | 188 | | /// Creates an instant playlist based on a given genre. |
| | | 189 | | /// </summary> |
| | | 190 | | /// <param name="name">The genre name.</param> |
| | | 191 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 192 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 193 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 194 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 195 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 196 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 197 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 198 | | /// <response code="200">Instant playlist returned.</response> |
| | | 199 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 200 | | [HttpGet("MusicGenres/{name}/InstantMix")] |
| | | 201 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 202 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromMusicGenreByName( |
| | | 203 | | [FromRoute, Required] string name, |
| | | 204 | | [FromQuery] Guid? userId, |
| | | 205 | | [FromQuery] int? limit, |
| | | 206 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 207 | | [FromQuery] bool? enableImages, |
| | | 208 | | [FromQuery] bool? enableUserData, |
| | | 209 | | [FromQuery] int? imageTypeLimit, |
| | | 210 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 211 | | { |
| | 0 | 212 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 213 | | var user = userId.IsNullOrEmpty() |
| | 0 | 214 | | ? null |
| | 0 | 215 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 216 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 217 | | .AddClientFields(User) |
| | 0 | 218 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 219 | | var items = _musicManager.GetInstantMixFromGenres(new[] { name }, user, dtoOptions); |
| | 0 | 220 | | return GetResult(items, user, limit, dtoOptions); |
| | | 221 | | } |
| | | 222 | | |
| | | 223 | | /// <summary> |
| | | 224 | | /// Creates an instant playlist based on a given artist. |
| | | 225 | | /// </summary> |
| | | 226 | | /// <param name="itemId">The item id.</param> |
| | | 227 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 228 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 229 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 230 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 231 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 232 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 233 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 234 | | /// <response code="200">Instant playlist returned.</response> |
| | | 235 | | /// <response code="404">Item not found.</response> |
| | | 236 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 237 | | [HttpGet("Artists/{itemId}/InstantMix")] |
| | | 238 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 239 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 240 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromArtists( |
| | | 241 | | [FromRoute, Required] Guid itemId, |
| | | 242 | | [FromQuery] Guid? userId, |
| | | 243 | | [FromQuery] int? limit, |
| | | 244 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 245 | | [FromQuery] bool? enableImages, |
| | | 246 | | [FromQuery] bool? enableUserData, |
| | | 247 | | [FromQuery] int? imageTypeLimit, |
| | | 248 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 249 | | { |
| | 0 | 250 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 251 | | var user = userId.IsNullOrEmpty() |
| | 0 | 252 | | ? null |
| | 0 | 253 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 254 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 0 | 255 | | if (item is null) |
| | | 256 | | { |
| | 0 | 257 | | return NotFound(); |
| | | 258 | | } |
| | | 259 | | |
| | 0 | 260 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 261 | | .AddClientFields(User) |
| | 0 | 262 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 263 | | var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions); |
| | 0 | 264 | | return GetResult(items, user, limit, dtoOptions); |
| | | 265 | | } |
| | | 266 | | |
| | | 267 | | /// <summary> |
| | | 268 | | /// Creates an instant playlist based on a given item. |
| | | 269 | | /// </summary> |
| | | 270 | | /// <param name="itemId">The item id.</param> |
| | | 271 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 272 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 273 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 274 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 275 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 276 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 277 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 278 | | /// <response code="200">Instant playlist returned.</response> |
| | | 279 | | /// <response code="404">Item not found.</response> |
| | | 280 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 281 | | [HttpGet("Items/{itemId}/InstantMix")] |
| | | 282 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 283 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 284 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromItem( |
| | | 285 | | [FromRoute, Required] Guid itemId, |
| | | 286 | | [FromQuery] Guid? userId, |
| | | 287 | | [FromQuery] int? limit, |
| | | 288 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 289 | | [FromQuery] bool? enableImages, |
| | | 290 | | [FromQuery] bool? enableUserData, |
| | | 291 | | [FromQuery] int? imageTypeLimit, |
| | | 292 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 293 | | { |
| | 0 | 294 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 295 | | var user = userId.IsNullOrEmpty() |
| | 0 | 296 | | ? null |
| | 0 | 297 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 298 | | var item = _libraryManager.GetItemById<BaseItem>(itemId, user); |
| | 0 | 299 | | if (item is null) |
| | | 300 | | { |
| | 0 | 301 | | return NotFound(); |
| | | 302 | | } |
| | | 303 | | |
| | 0 | 304 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 305 | | .AddClientFields(User) |
| | 0 | 306 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 307 | | var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions); |
| | 0 | 308 | | return GetResult(items, user, limit, dtoOptions); |
| | | 309 | | } |
| | | 310 | | |
| | | 311 | | /// <summary> |
| | | 312 | | /// Creates an instant playlist based on a given artist. |
| | | 313 | | /// </summary> |
| | | 314 | | /// <param name="id">The item id.</param> |
| | | 315 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 316 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 317 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 318 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 319 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 320 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 321 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 322 | | /// <response code="200">Instant playlist returned.</response> |
| | | 323 | | /// <response code="404">Item not found.</response> |
| | | 324 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 325 | | [HttpGet("Artists/InstantMix")] |
| | | 326 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 327 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 328 | | [Obsolete("Use GetInstantMixFromArtists")] |
| | | 329 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromArtists2( |
| | | 330 | | [FromQuery, Required] Guid id, |
| | | 331 | | [FromQuery] Guid? userId, |
| | | 332 | | [FromQuery] int? limit, |
| | | 333 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 334 | | [FromQuery] bool? enableImages, |
| | | 335 | | [FromQuery] bool? enableUserData, |
| | | 336 | | [FromQuery] int? imageTypeLimit, |
| | | 337 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 338 | | { |
| | | 339 | | return GetInstantMixFromArtists( |
| | | 340 | | id, |
| | | 341 | | userId, |
| | | 342 | | limit, |
| | | 343 | | fields, |
| | | 344 | | enableImages, |
| | | 345 | | enableUserData, |
| | | 346 | | imageTypeLimit, |
| | | 347 | | enableImageTypes); |
| | | 348 | | } |
| | | 349 | | |
| | | 350 | | /// <summary> |
| | | 351 | | /// Creates an instant playlist based on a given genre. |
| | | 352 | | /// </summary> |
| | | 353 | | /// <param name="id">The item id.</param> |
| | | 354 | | /// <param name="userId">Optional. Filter by user id, and attach user data.</param> |
| | | 355 | | /// <param name="limit">Optional. The maximum number of records to return.</param> |
| | | 356 | | /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param> |
| | | 357 | | /// <param name="enableImages">Optional. Include image information in output.</param> |
| | | 358 | | /// <param name="enableUserData">Optional. Include user data.</param> |
| | | 359 | | /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param> |
| | | 360 | | /// <param name="enableImageTypes">Optional. The image types to include in the output.</param> |
| | | 361 | | /// <response code="200">Instant playlist returned.</response> |
| | | 362 | | /// <response code="404">Item not found.</response> |
| | | 363 | | /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the playlist items.</returns> |
| | | 364 | | [HttpGet("MusicGenres/InstantMix")] |
| | | 365 | | [ProducesResponseType(StatusCodes.Status200OK)] |
| | | 366 | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | 367 | | public ActionResult<QueryResult<BaseItemDto>> GetInstantMixFromMusicGenreById( |
| | | 368 | | [FromQuery, Required] Guid id, |
| | | 369 | | [FromQuery] Guid? userId, |
| | | 370 | | [FromQuery] int? limit, |
| | | 371 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ItemFields[] fields, |
| | | 372 | | [FromQuery] bool? enableImages, |
| | | 373 | | [FromQuery] bool? enableUserData, |
| | | 374 | | [FromQuery] int? imageTypeLimit, |
| | | 375 | | [FromQuery, ModelBinder(typeof(CommaDelimitedCollectionModelBinder))] ImageType[] enableImageTypes) |
| | | 376 | | { |
| | 0 | 377 | | userId = RequestHelpers.GetUserId(User, userId); |
| | 0 | 378 | | var user = userId.IsNullOrEmpty() |
| | 0 | 379 | | ? null |
| | 0 | 380 | | : _userManager.GetUserById(userId.Value); |
| | 0 | 381 | | var item = _libraryManager.GetItemById<BaseItem>(id, user); |
| | 0 | 382 | | if (item is null) |
| | | 383 | | { |
| | 0 | 384 | | return NotFound(); |
| | | 385 | | } |
| | | 386 | | |
| | 0 | 387 | | var dtoOptions = new DtoOptions { Fields = fields } |
| | 0 | 388 | | .AddClientFields(User) |
| | 0 | 389 | | .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); |
| | 0 | 390 | | var items = _musicManager.GetInstantMixFromItem(item, user, dtoOptions); |
| | 0 | 391 | | return GetResult(items, user, limit, dtoOptions); |
| | | 392 | | } |
| | | 393 | | |
| | | 394 | | private QueryResult<BaseItemDto> GetResult(IReadOnlyList<BaseItem> items, User? user, int? limit, DtoOptions dtoOpti |
| | | 395 | | { |
| | 0 | 396 | | var totalCount = items.Count; |
| | | 397 | | |
| | 0 | 398 | | if (limit.HasValue && limit < items.Count) |
| | | 399 | | { |
| | 0 | 400 | | items = items.Take(limit.Value).ToArray(); |
| | | 401 | | } |
| | | 402 | | |
| | 0 | 403 | | var result = new QueryResult<BaseItemDto>( |
| | 0 | 404 | | 0, |
| | 0 | 405 | | totalCount, |
| | 0 | 406 | | _dtoService.GetBaseItemDtos(items, dtoOptions, user)); |
| | | 407 | | |
| | 0 | 408 | | return result; |
| | | 409 | | } |
| | | 410 | | } |