ArtistsController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.Linq;
  4. using Jellyfin.Api.Constants;
  5. using Jellyfin.Api.Extensions;
  6. using Jellyfin.Api.Helpers;
  7. using Jellyfin.Api.ModelBinders;
  8. using Jellyfin.Data.Entities;
  9. using Jellyfin.Data.Enums;
  10. using MediaBrowser.Controller.Dto;
  11. using MediaBrowser.Controller.Entities;
  12. using MediaBrowser.Controller.Library;
  13. using MediaBrowser.Model.Dto;
  14. using MediaBrowser.Model.Entities;
  15. using MediaBrowser.Model.Querying;
  16. using Microsoft.AspNetCore.Authorization;
  17. using Microsoft.AspNetCore.Http;
  18. using Microsoft.AspNetCore.Mvc;
  19. namespace Jellyfin.Api.Controllers;
  20. /// <summary>
  21. /// The artists controller.
  22. /// </summary>
  23. [Route("Artists")]
  24. [Authorize(Policy = Policies.DefaultAuthorization)]
  25. public class ArtistsController : BaseJellyfinApiController
  26. {
  27. private readonly ILibraryManager _libraryManager;
  28. private readonly IUserManager _userManager;
  29. private readonly IDtoService _dtoService;
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="ArtistsController"/> class.
  32. /// </summary>
  33. /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
  34. /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
  35. /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
  36. public ArtistsController(
  37. ILibraryManager libraryManager,
  38. IUserManager userManager,
  39. IDtoService dtoService)
  40. {
  41. _libraryManager = libraryManager;
  42. _userManager = userManager;
  43. _dtoService = dtoService;
  44. }
  45. /// <summary>
  46. /// Gets all artists from a given item, folder, or the entire library.
  47. /// </summary>
  48. /// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
  49. /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
  50. /// <param name="limit">Optional. The maximum number of records to return.</param>
  51. /// <param name="searchTerm">Optional. Search term.</param>
  52. /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
  53. /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
  54. /// <param name="excludeItemTypes">Optional. If specified, results will be filtered out based on item type. This allows multiple, comma delimited.</param>
  55. /// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.</param>
  56. /// <param name="filters">Optional. Specify additional filters to apply.</param>
  57. /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
  58. /// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
  59. /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimited.</param>
  60. /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimited.</param>
  61. /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimited.</param>
  62. /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimited.</param>
  63. /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimited.</param>
  64. /// <param name="enableUserData">Optional, include user data.</param>
  65. /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
  66. /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
  67. /// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
  68. /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person ids.</param>
  69. /// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.</param>
  70. /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimited.</param>
  71. /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimited.</param>
  72. /// <param name="userId">User id.</param>
  73. /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a given input string.</param>
  74. /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</param>
  75. /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</param>
  76. /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited.</param>
  77. /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
  78. /// <param name="enableImages">Optional, include image information in output.</param>
  79. /// <param name="enableTotalRecordCount">Total record count.</param>
  80. /// <response code="200">Artists returned.</response>
  81. /// <returns>An <see cref="OkResult"/> containing the artists.</returns>
  82. [HttpGet]
  83. [ProducesResponseType(StatusCodes.Status200OK)]
  84. public ActionResult<QueryResult<BaseItemDto>> GetArtists(
  85. [FromQuery] double? minCommunityRating,
  86. [FromQuery] int? startIndex,
  87. [FromQuery] int? limit,
  88. [FromQuery] string? searchTerm,
  89. [FromQuery] Guid? parentId,
  90. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
  91. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] excludeItemTypes,
  92. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
  93. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
  94. [FromQuery] bool? isFavorite,
  95. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
  96. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] genres,
  97. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] genreIds,
  98. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] officialRatings,
  99. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] tags,
  100. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] int[] years,
  101. [FromQuery] bool? enableUserData,
  102. [FromQuery] int? imageTypeLimit,
  103. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
  104. [FromQuery] string? person,
  105. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] personIds,
  106. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] personTypes,
  107. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] studios,
  108. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] studioIds,
  109. [FromQuery] Guid? userId,
  110. [FromQuery] string? nameStartsWithOrGreater,
  111. [FromQuery] string? nameStartsWith,
  112. [FromQuery] string? nameLessThan,
  113. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
  114. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] SortOrder[] sortOrder,
  115. [FromQuery] bool? enableImages = true,
  116. [FromQuery] bool enableTotalRecordCount = true)
  117. {
  118. var dtoOptions = new DtoOptions { Fields = fields }
  119. .AddClientFields(User)
  120. .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
  121. User? user = null;
  122. BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
  123. if (userId.HasValue && !userId.Equals(default))
  124. {
  125. user = _userManager.GetUserById(userId.Value);
  126. }
  127. var query = new InternalItemsQuery(user)
  128. {
  129. ExcludeItemTypes = excludeItemTypes,
  130. IncludeItemTypes = includeItemTypes,
  131. MediaTypes = mediaTypes,
  132. StartIndex = startIndex,
  133. Limit = limit,
  134. IsFavorite = isFavorite,
  135. NameLessThan = nameLessThan,
  136. NameStartsWith = nameStartsWith,
  137. NameStartsWithOrGreater = nameStartsWithOrGreater,
  138. Tags = tags,
  139. OfficialRatings = officialRatings,
  140. Genres = genres,
  141. GenreIds = genreIds,
  142. StudioIds = studioIds,
  143. Person = person,
  144. PersonIds = personIds,
  145. PersonTypes = personTypes,
  146. Years = years,
  147. MinCommunityRating = minCommunityRating,
  148. DtoOptions = dtoOptions,
  149. SearchTerm = searchTerm,
  150. EnableTotalRecordCount = enableTotalRecordCount,
  151. OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder)
  152. };
  153. if (parentId.HasValue)
  154. {
  155. if (parentItem is Folder)
  156. {
  157. query.AncestorIds = new[] { parentId.Value };
  158. }
  159. else
  160. {
  161. query.ItemIds = new[] { parentId.Value };
  162. }
  163. }
  164. // Studios
  165. if (studios.Length != 0)
  166. {
  167. query.StudioIds = studios.Select(i =>
  168. {
  169. try
  170. {
  171. return _libraryManager.GetStudio(i);
  172. }
  173. catch
  174. {
  175. return null;
  176. }
  177. }).Where(i => i is not null).Select(i => i!.Id).ToArray();
  178. }
  179. foreach (var filter in filters)
  180. {
  181. switch (filter)
  182. {
  183. case ItemFilter.Dislikes:
  184. query.IsLiked = false;
  185. break;
  186. case ItemFilter.IsFavorite:
  187. query.IsFavorite = true;
  188. break;
  189. case ItemFilter.IsFavoriteOrLikes:
  190. query.IsFavoriteOrLiked = true;
  191. break;
  192. case ItemFilter.IsFolder:
  193. query.IsFolder = true;
  194. break;
  195. case ItemFilter.IsNotFolder:
  196. query.IsFolder = false;
  197. break;
  198. case ItemFilter.IsPlayed:
  199. query.IsPlayed = true;
  200. break;
  201. case ItemFilter.IsResumable:
  202. query.IsResumable = true;
  203. break;
  204. case ItemFilter.IsUnplayed:
  205. query.IsPlayed = false;
  206. break;
  207. case ItemFilter.Likes:
  208. query.IsLiked = true;
  209. break;
  210. }
  211. }
  212. var result = _libraryManager.GetArtists(query);
  213. var dtos = result.Items.Select(i =>
  214. {
  215. var (baseItem, itemCounts) = i;
  216. var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user);
  217. if (includeItemTypes.Length != 0)
  218. {
  219. dto.ChildCount = itemCounts.ItemCount;
  220. dto.ProgramCount = itemCounts.ProgramCount;
  221. dto.SeriesCount = itemCounts.SeriesCount;
  222. dto.EpisodeCount = itemCounts.EpisodeCount;
  223. dto.MovieCount = itemCounts.MovieCount;
  224. dto.TrailerCount = itemCounts.TrailerCount;
  225. dto.AlbumCount = itemCounts.AlbumCount;
  226. dto.SongCount = itemCounts.SongCount;
  227. dto.ArtistCount = itemCounts.ArtistCount;
  228. }
  229. return dto;
  230. });
  231. return new QueryResult<BaseItemDto>(
  232. query.StartIndex,
  233. result.TotalRecordCount,
  234. dtos.ToArray());
  235. }
  236. /// <summary>
  237. /// Gets all album artists from a given item, folder, or the entire library.
  238. /// </summary>
  239. /// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
  240. /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
  241. /// <param name="limit">Optional. The maximum number of records to return.</param>
  242. /// <param name="searchTerm">Optional. Search term.</param>
  243. /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
  244. /// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
  245. /// <param name="excludeItemTypes">Optional. If specified, results will be filtered out based on item type. This allows multiple, comma delimited.</param>
  246. /// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.</param>
  247. /// <param name="filters">Optional. Specify additional filters to apply.</param>
  248. /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
  249. /// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
  250. /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimited.</param>
  251. /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimited.</param>
  252. /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimited.</param>
  253. /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimited.</param>
  254. /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimited.</param>
  255. /// <param name="enableUserData">Optional, include user data.</param>
  256. /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
  257. /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
  258. /// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
  259. /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person ids.</param>
  260. /// <param name="personTypes">Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited.</param>
  261. /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimited.</param>
  262. /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimited.</param>
  263. /// <param name="userId">User id.</param>
  264. /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a given input string.</param>
  265. /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</param>
  266. /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</param>
  267. /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited.</param>
  268. /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
  269. /// <param name="enableImages">Optional, include image information in output.</param>
  270. /// <param name="enableTotalRecordCount">Total record count.</param>
  271. /// <response code="200">Album artists returned.</response>
  272. /// <returns>An <see cref="OkResult"/> containing the album artists.</returns>
  273. [HttpGet("AlbumArtists")]
  274. [ProducesResponseType(StatusCodes.Status200OK)]
  275. public ActionResult<QueryResult<BaseItemDto>> GetAlbumArtists(
  276. [FromQuery] double? minCommunityRating,
  277. [FromQuery] int? startIndex,
  278. [FromQuery] int? limit,
  279. [FromQuery] string? searchTerm,
  280. [FromQuery] Guid? parentId,
  281. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
  282. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] excludeItemTypes,
  283. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
  284. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFilter[] filters,
  285. [FromQuery] bool? isFavorite,
  286. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes,
  287. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] genres,
  288. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] genreIds,
  289. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] officialRatings,
  290. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] tags,
  291. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] int[] years,
  292. [FromQuery] bool? enableUserData,
  293. [FromQuery] int? imageTypeLimit,
  294. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
  295. [FromQuery] string? person,
  296. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] personIds,
  297. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] personTypes,
  298. [FromQuery, ModelBinder(typeof(PipeDelimitedArrayModelBinder))] string[] studios,
  299. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] studioIds,
  300. [FromQuery] Guid? userId,
  301. [FromQuery] string? nameStartsWithOrGreater,
  302. [FromQuery] string? nameStartsWith,
  303. [FromQuery] string? nameLessThan,
  304. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
  305. [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] SortOrder[] sortOrder,
  306. [FromQuery] bool? enableImages = true,
  307. [FromQuery] bool enableTotalRecordCount = true)
  308. {
  309. var dtoOptions = new DtoOptions { Fields = fields }
  310. .AddClientFields(User)
  311. .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
  312. User? user = null;
  313. BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
  314. if (userId.HasValue && !userId.Equals(default))
  315. {
  316. user = _userManager.GetUserById(userId.Value);
  317. }
  318. var query = new InternalItemsQuery(user)
  319. {
  320. ExcludeItemTypes = excludeItemTypes,
  321. IncludeItemTypes = includeItemTypes,
  322. MediaTypes = mediaTypes,
  323. StartIndex = startIndex,
  324. Limit = limit,
  325. IsFavorite = isFavorite,
  326. NameLessThan = nameLessThan,
  327. NameStartsWith = nameStartsWith,
  328. NameStartsWithOrGreater = nameStartsWithOrGreater,
  329. Tags = tags,
  330. OfficialRatings = officialRatings,
  331. Genres = genres,
  332. GenreIds = genreIds,
  333. StudioIds = studioIds,
  334. Person = person,
  335. PersonIds = personIds,
  336. PersonTypes = personTypes,
  337. Years = years,
  338. MinCommunityRating = minCommunityRating,
  339. DtoOptions = dtoOptions,
  340. SearchTerm = searchTerm,
  341. EnableTotalRecordCount = enableTotalRecordCount,
  342. OrderBy = RequestHelpers.GetOrderBy(sortBy, sortOrder)
  343. };
  344. if (parentId.HasValue)
  345. {
  346. if (parentItem is Folder)
  347. {
  348. query.AncestorIds = new[] { parentId.Value };
  349. }
  350. else
  351. {
  352. query.ItemIds = new[] { parentId.Value };
  353. }
  354. }
  355. // Studios
  356. if (studios.Length != 0)
  357. {
  358. query.StudioIds = studios.Select(i =>
  359. {
  360. try
  361. {
  362. return _libraryManager.GetStudio(i);
  363. }
  364. catch
  365. {
  366. return null;
  367. }
  368. }).Where(i => i is not null).Select(i => i!.Id).ToArray();
  369. }
  370. foreach (var filter in filters)
  371. {
  372. switch (filter)
  373. {
  374. case ItemFilter.Dislikes:
  375. query.IsLiked = false;
  376. break;
  377. case ItemFilter.IsFavorite:
  378. query.IsFavorite = true;
  379. break;
  380. case ItemFilter.IsFavoriteOrLikes:
  381. query.IsFavoriteOrLiked = true;
  382. break;
  383. case ItemFilter.IsFolder:
  384. query.IsFolder = true;
  385. break;
  386. case ItemFilter.IsNotFolder:
  387. query.IsFolder = false;
  388. break;
  389. case ItemFilter.IsPlayed:
  390. query.IsPlayed = true;
  391. break;
  392. case ItemFilter.IsResumable:
  393. query.IsResumable = true;
  394. break;
  395. case ItemFilter.IsUnplayed:
  396. query.IsPlayed = false;
  397. break;
  398. case ItemFilter.Likes:
  399. query.IsLiked = true;
  400. break;
  401. }
  402. }
  403. var result = _libraryManager.GetAlbumArtists(query);
  404. var dtos = result.Items.Select(i =>
  405. {
  406. var (baseItem, itemCounts) = i;
  407. var dto = _dtoService.GetItemByNameDto(baseItem, dtoOptions, null, user);
  408. if (includeItemTypes.Length != 0)
  409. {
  410. dto.ChildCount = itemCounts.ItemCount;
  411. dto.ProgramCount = itemCounts.ProgramCount;
  412. dto.SeriesCount = itemCounts.SeriesCount;
  413. dto.EpisodeCount = itemCounts.EpisodeCount;
  414. dto.MovieCount = itemCounts.MovieCount;
  415. dto.TrailerCount = itemCounts.TrailerCount;
  416. dto.AlbumCount = itemCounts.AlbumCount;
  417. dto.SongCount = itemCounts.SongCount;
  418. dto.ArtistCount = itemCounts.ArtistCount;
  419. }
  420. return dto;
  421. });
  422. return new QueryResult<BaseItemDto>(
  423. query.StartIndex,
  424. result.TotalRecordCount,
  425. dtos.ToArray());
  426. }
  427. /// <summary>
  428. /// Gets an artist by name.
  429. /// </summary>
  430. /// <param name="name">Studio name.</param>
  431. /// <param name="userId">Optional. Filter by user id, and attach user data.</param>
  432. /// <response code="200">Artist returned.</response>
  433. /// <returns>An <see cref="OkResult"/> containing the artist.</returns>
  434. [HttpGet("{name}")]
  435. [ProducesResponseType(StatusCodes.Status200OK)]
  436. public ActionResult<BaseItemDto> GetArtistByName([FromRoute, Required] string name, [FromQuery] Guid? userId)
  437. {
  438. var dtoOptions = new DtoOptions().AddClientFields(User);
  439. var item = _libraryManager.GetArtist(name, dtoOptions);
  440. if (userId.HasValue && !userId.Value.Equals(default))
  441. {
  442. var user = _userManager.GetUserById(userId.Value);
  443. return _dtoService.GetBaseItemDto(item, dtoOptions, user);
  444. }
  445. return _dtoService.GetBaseItemDto(item, dtoOptions);
  446. }
  447. }