ArtistsController.cs 24 KB

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