YearsController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using Jellyfin.Api.Extensions;
  6. using Jellyfin.Api.Helpers;
  7. using Jellyfin.Data.Entities;
  8. using MediaBrowser.Controller.Dto;
  9. using MediaBrowser.Controller.Entities;
  10. using MediaBrowser.Controller.Library;
  11. using MediaBrowser.Model.Dto;
  12. using MediaBrowser.Model.Querying;
  13. using Microsoft.AspNetCore.Http;
  14. using Microsoft.AspNetCore.Mvc;
  15. namespace Jellyfin.Api.Controllers
  16. {
  17. /// <summary>
  18. /// Years controller.
  19. /// </summary>
  20. public class YearsController : BaseJellyfinApiController
  21. {
  22. private readonly ILibraryManager _libraryManager;
  23. private readonly IUserManager _userManager;
  24. private readonly IDtoService _dtoService;
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref="YearsController"/> class.
  27. /// </summary>
  28. /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
  29. /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
  30. /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
  31. public YearsController(
  32. ILibraryManager libraryManager,
  33. IUserManager userManager,
  34. IDtoService dtoService)
  35. {
  36. _libraryManager = libraryManager;
  37. _userManager = userManager;
  38. _dtoService = dtoService;
  39. }
  40. /// <summary>
  41. /// Get years.
  42. /// </summary>
  43. /// <param name="maxOfficialRating">Optional. Filter by maximum official rating (PG, PG-13, TV-MA, etc).</param>
  44. /// <param name="hasThemeSong">Optional. Filter by items with theme songs.</param>
  45. /// <param name="hasThemeVideo">Optional. Filter by items with theme videos.</param>
  46. /// <param name="hasSubtitles">Optional. Filter by items with subtitles.</param>
  47. /// <param name="hasSpecialFeatures">Optional. Filter by items with special features.</param>
  48. /// <param name="hasTrailer">Optional. Filter by items with trailers.</param>
  49. /// <param name="adjacentTo">Optional. Return items that are siblings of a supplied item.</param>
  50. /// <param name="minIndexNumber">Optional. Filter by minimum index number.</param>
  51. /// <param name="parentIndexNumber">Optional. Filter by parent index number.</param>
  52. /// <param name="hasParentalRating">Optional. filter by items that have or do not have a parental rating.</param>
  53. /// <param name="isHd">Optional. Filter by items that are HD or not.</param>
  54. /// <param name="is4k">Optional. Filter by items that are 4K or not.</param>
  55. /// <param name="locationTypes">Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimited.</param>
  56. /// <param name="excludeLocationTypes">Optional. If specified, results will be excluded based on LocationType. This allows multiple, comma delimited.</param>
  57. /// <param name="isMissing">Optional. Filter by items that are missing episodes or not.</param>
  58. /// <param name="isUnaired">Optional. Filter by items that are unaired episodes or not.</param>
  59. /// <param name="minCommunityRating">Optional. Filter by minimum community rating.</param>
  60. /// <param name="minCriticRating">Optional. Filter by minimum critic rating.</param>
  61. /// <param name="airedDuringSeason">Gets all episodes that aired during a season, including specials.</param>
  62. /// <param name="minPremiereDate">Optional. The minimum premiere date.</param>
  63. /// <param name="minDateLastSaved">Optional. The minimum last saved date.</param>
  64. /// <param name="minDateLastSavedForUser">Optional. The minimum last saved date for user.</param>
  65. /// <param name="maxPremiereDate">Optional. The maximum premiere date.</param>
  66. /// <param name="hasOverview">Optional. Filter by items that have an overview or not.</param>
  67. /// <param name="hasImdbId">Optional. Filter by items that have an imdb id or not.</param>
  68. /// <param name="hasTmdbId">Optional. Filter by items that have a tmdb id or not.</param>
  69. /// <param name="hasTvdbId">Optional. Filter by items that have a tvdb id or not.</param>
  70. /// <param name="excludeItemIds">Optional. If specified, results will be filtered by excluding item ids. This allows multiple, comma delimited.</param>
  71. /// <param name="startIndex">Skips over a given number of items within the results. Use for paging.</param>
  72. /// <param name="limit">Optional. The maximum number of records to return.</param>
  73. /// <param name="searchTerm">Optional. Search term.</param>
  74. /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
  75. /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
  76. /// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
  77. /// <param name="excludeItemTypes">Optional. If specified, results will be excluded based on item type. This allows multiple, comma delimited.</param>
  78. /// <param name="includeItemTypes">Optional. If specified, results will be included based on item type. This allows multiple, comma delimited.</param>
  79. /// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimited. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
  80. /// <param name="isFavorite">Optional. Filter by items that are marked as favorite, or not.</param>
  81. /// <param name="mediaTypes">Optional. Filter by MediaType. Allows multiple, comma delimited.</param>
  82. /// <param name="imageTypes">Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.</param>
  83. /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimited. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
  84. /// <param name="isPlayed">Optional. Filter by items that are played, or not.</param>
  85. /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimited.</param>
  86. /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimited.</param>
  87. /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimited.</param>
  88. /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimited.</param>
  89. /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimited.</param>
  90. /// <param name="enableUserData">Optional. Include user data.</param>
  91. /// <param name="imageTypeLimit">Optional. The max number of images to return, per image type.</param>
  92. /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
  93. /// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
  94. /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person ids.</param>
  95. /// <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>
  96. /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimited.</param>
  97. /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimited.</param>
  98. /// <param name="artists">Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimited.</param>
  99. /// <param name="excludeArtistIds">Optional. If specified, results will be excluded based on artist id. This allows multiple, pipe delimited.</param>
  100. /// <param name="artistIds">Optional. If specified, results will be filtered based on artist id. This allows multiple, pipe delimited.</param>
  101. /// <param name="albumArtistIds">Optional. If specified, results will be filtered based on album artist id. This allows multiple, pipe delimited.</param>
  102. /// <param name="contributingArtistIds">Optional. If specified, results will be filtered based on contributing artist id. This allows multiple, pipe delimited.</param>
  103. /// <param name="albums">Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimited.</param>
  104. /// <param name="albumIds">Optional. If specified, results will be filtered based on album id. This allows multiple, pipe delimited.</param>
  105. /// <param name="ids">Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.</param>
  106. /// <param name="videoTypes">Optional. Filter by VideoType (videofile, dvd, bluray, iso). Allows multiple, comma delimited.</param>
  107. /// <param name="userId">User Id.</param>
  108. /// <param name="minOfficialRating">Optional. Filter by minimum official rating (PG, PG-13, TV-MA, etc).</param>
  109. /// <param name="isLocked">Optional. Filter by items that are locked.</param>
  110. /// <param name="isPlaceholder">Optional. Filter by items that are placeholders.</param>
  111. /// <param name="hasOfficialRating">Optional. Filter by items that have official ratings.</param>
  112. /// <param name="collapseBoxSetItems">Whether or not to hide items behind their boxsets.</param>
  113. /// <param name="minWidth">Min width.</param>
  114. /// <param name="minHeight">Min height.</param>
  115. /// <param name="maxWidth">Max width.</param>
  116. /// <param name="maxHeight">Max height.</param>
  117. /// <param name="is3d">Optional. Filter by items that are 3D, or not.</param>
  118. /// <param name="seriesStatus">Optional. Filter by Series Status. Allows multiple, comma delimited.</param>
  119. /// <param name="nameStartsWithOrGreater">Optional. Filter by items whose name is sorted equally or greater than a given input string.</param>
  120. /// <param name="nameStartsWith">Optional. Filter by items whose name is sorted equally than a given input string.</param>
  121. /// <param name="nameLessThan">Optional. Filter by items whose name is equally or lesser than a given input string.</param>
  122. /// <param name="recursive">Search recursively.</param>
  123. /// <param name="enableImages">Optional. Include image information in output.</param>
  124. /// <param name="enableTotalRecordCount">Return total record count.</param>
  125. /// <response code="200">Year query returned.</response>
  126. /// <returns> A <see cref="QueryResult{BaseItemDto}"/> containing the year result.</returns>
  127. [HttpGet]
  128. [ProducesResponseType(StatusCodes.Status200OK)]
  129. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "maxOfficialRating", Justification = "Imported from ServiceStack")]
  130. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasThemeSong", Justification = "Imported from ServiceStack")]
  131. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasThemeVideo", Justification = "Imported from ServiceStack")]
  132. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasSubtitles", Justification = "Imported from ServiceStack")]
  133. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasSpecialFeatures", Justification = "Imported from ServiceStack")]
  134. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasTrailer", Justification = "Imported from ServiceStack")]
  135. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "adjacentTo", Justification = "Imported from ServiceStack")]
  136. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minIndexNumber", Justification = "Imported from ServiceStack")]
  137. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "parentIndexNumber", Justification = "Imported from ServiceStack")]
  138. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasParentalRating", Justification = "Imported from ServiceStack")]
  139. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isHd", Justification = "Imported from ServiceStack")]
  140. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "is4k", Justification = "Imported from ServiceStack")]
  141. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "locationTypes", Justification = "Imported from ServiceStack")]
  142. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "excludeLocationTypes", Justification = "Imported from ServiceStack")]
  143. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isMissing", Justification = "Imported from ServiceStack")]
  144. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isUnaired", Justification = "Imported from ServiceStack")]
  145. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minCommunityRating", Justification = "Imported from ServiceStack")]
  146. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minCriticRating", Justification = "Imported from ServiceStack")]
  147. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "airedDuringSeason", Justification = "Imported from ServiceStack")]
  148. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minPremiereDate", Justification = "Imported from ServiceStack")]
  149. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minDateLastSaved", Justification = "Imported from ServiceStack")]
  150. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minDateLastSavedForUser", Justification = "Imported from ServiceStack")]
  151. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "maxPremiereDate", Justification = "Imported from ServiceStack")]
  152. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasOverview", Justification = "Imported from ServiceStack")]
  153. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasImdbId", Justification = "Imported from ServiceStack")]
  154. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasTmdbId", Justification = "Imported from ServiceStack")]
  155. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasTvdbId", Justification = "Imported from ServiceStack")]
  156. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "excludeItemIds", Justification = "Imported from ServiceStack")]
  157. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "searchTerm", Justification = "Imported from ServiceStack")]
  158. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "filters", Justification = "Imported from ServiceStack")]
  159. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isFavorite", Justification = "Imported from ServiceStack")]
  160. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "imageTypes", Justification = "Imported from ServiceStack")]
  161. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isPlayed", Justification = "Imported from ServiceStack")]
  162. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "genres", Justification = "Imported from ServiceStack")]
  163. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "genreIds", Justification = "Imported from ServiceStack")]
  164. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "officialRatings", Justification = "Imported from ServiceStack")]
  165. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "tags", Justification = "Imported from ServiceStack")]
  166. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "years", Justification = "Imported from ServiceStack")]
  167. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "person", Justification = "Imported from ServiceStack")]
  168. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "personIds", Justification = "Imported from ServiceStack")]
  169. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "personTypes", Justification = "Imported from ServiceStack")]
  170. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "studios", Justification = "Imported from ServiceStack")]
  171. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "studioIds", Justification = "Imported from ServiceStack")]
  172. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "artists", Justification = "Imported from ServiceStack")]
  173. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "excludeArtistIds", Justification = "Imported from ServiceStack")]
  174. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "artistIds", Justification = "Imported from ServiceStack")]
  175. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "albumArtistIds", Justification = "Imported from ServiceStack")]
  176. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "contributingArtistIds", Justification = "Imported from ServiceStack")]
  177. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "personIds", Justification = "Imported from ServiceStack")]
  178. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "personTypes", Justification = "Imported from ServiceStack")]
  179. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "studios", Justification = "Imported from ServiceStack")]
  180. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "studioIds", Justification = "Imported from ServiceStack")]
  181. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "artists", Justification = "Imported from ServiceStack")]
  182. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "excludeArtistIds", Justification = "Imported from ServiceStack")]
  183. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "artistIds", Justification = "Imported from ServiceStack")]
  184. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "albumArtistIds", Justification = "Imported from ServiceStack")]
  185. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "contributingArtistIds", Justification = "Imported from ServiceStack")]
  186. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "albums", Justification = "Imported from ServiceStack")]
  187. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "albumIds", Justification = "Imported from ServiceStack")]
  188. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "ids", Justification = "Imported from ServiceStack")]
  189. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "videoTypes", Justification = "Imported from ServiceStack")]
  190. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isLocked", Justification = "Imported from ServiceStack")]
  191. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isPlaceholder", Justification = "Imported from ServiceStack")]
  192. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "hasOfficialRating", Justification = "Imported from ServiceStack")]
  193. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "collapseBoxSetItems", Justification = "Imported from ServiceStack")]
  194. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minWidth", Justification = "Imported from ServiceStack")]
  195. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "minHeight", Justification = "Imported from ServiceStack")]
  196. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "maxWidth", Justification = "Imported from ServiceStack")]
  197. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "maxHeight", Justification = "Imported from ServiceStack")]
  198. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "is3d", Justification = "Imported from ServiceStack")]
  199. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "seriesStatus", Justification = "Imported from ServiceStack")]
  200. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "nameStartsWithOrGreater", Justification = "Imported from ServiceStack")]
  201. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "nameStartsWith", Justification = "Imported from ServiceStack")]
  202. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "nameLessThan", Justification = "Imported from ServiceStack")]
  203. [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "enableTotalRecordCount", Justification = "Imported from ServiceStack")]
  204. public ActionResult<QueryResult<BaseItemDto>> GetYears(
  205. [FromQuery] string maxOfficialRating,
  206. [FromQuery] bool? hasThemeSong,
  207. [FromQuery] bool? hasThemeVideo,
  208. [FromQuery] bool? hasSubtitles,
  209. [FromQuery] bool? hasSpecialFeatures,
  210. [FromQuery] bool? hasTrailer,
  211. [FromQuery] string adjacentTo,
  212. [FromQuery] int? minIndexNumber,
  213. [FromQuery] int? parentIndexNumber,
  214. [FromQuery] bool? hasParentalRating,
  215. [FromQuery] bool? isHd,
  216. [FromQuery] bool? is4k,
  217. [FromQuery] string locationTypes,
  218. [FromQuery] string excludeLocationTypes,
  219. [FromQuery] bool? isMissing,
  220. [FromQuery] bool? isUnaired,
  221. [FromQuery] double? minCommunityRating,
  222. [FromQuery] double? minCriticRating,
  223. [FromQuery] int? airedDuringSeason,
  224. [FromQuery] DateTime? minPremiereDate,
  225. [FromQuery] DateTime? minDateLastSaved,
  226. [FromQuery] DateTime? minDateLastSavedForUser,
  227. [FromQuery] DateTime? maxPremiereDate,
  228. [FromQuery] bool? hasOverview,
  229. [FromQuery] bool? hasImdbId,
  230. [FromQuery] bool? hasTmdbId,
  231. [FromQuery] bool? hasTvdbId,
  232. [FromQuery] string excludeItemIds,
  233. [FromQuery] int? startIndex,
  234. [FromQuery] int? limit,
  235. [FromQuery] string searchTerm,
  236. [FromQuery] string sortOrder,
  237. [FromQuery] string parentId,
  238. [FromQuery] string fields,
  239. [FromQuery] string excludeItemTypes,
  240. [FromQuery] string includeItemTypes,
  241. [FromQuery] string filters,
  242. [FromQuery] bool? isFavorite,
  243. [FromQuery] string mediaTypes,
  244. [FromQuery] string imageTypes,
  245. [FromQuery] string sortBy,
  246. [FromQuery] bool? isPlayed,
  247. [FromQuery] string genres,
  248. [FromQuery] string genreIds,
  249. [FromQuery] string officialRatings,
  250. [FromQuery] string tags,
  251. [FromQuery] string years,
  252. [FromQuery] bool? enableUserData,
  253. [FromQuery] int? imageTypeLimit,
  254. [FromQuery] string enableImageTypes,
  255. [FromQuery] string person,
  256. [FromQuery] string personIds,
  257. [FromQuery] string personTypes,
  258. [FromQuery] string studios,
  259. [FromQuery] string studioIds,
  260. [FromQuery] string artists,
  261. [FromQuery] string excludeArtistIds,
  262. [FromQuery] string artistIds,
  263. [FromQuery] string albumArtistIds,
  264. [FromQuery] string contributingArtistIds,
  265. [FromQuery] string albums,
  266. [FromQuery] string albumIds,
  267. [FromQuery] string ids,
  268. [FromQuery] string videoTypes,
  269. [FromQuery] Guid userId,
  270. [FromQuery] string minOfficialRating,
  271. [FromQuery] bool? isLocked,
  272. [FromQuery] bool? isPlaceholder,
  273. [FromQuery] bool? hasOfficialRating,
  274. [FromQuery] bool? collapseBoxSetItems,
  275. [FromQuery] int? minWidth,
  276. [FromQuery] int? minHeight,
  277. [FromQuery] int? maxWidth,
  278. [FromQuery] int? maxHeight,
  279. [FromQuery] bool? is3d,
  280. [FromQuery] string seriesStatus,
  281. [FromQuery] string nameStartsWithOrGreater,
  282. [FromQuery] string nameStartsWith,
  283. [FromQuery] string nameLessThan,
  284. [FromQuery] bool recursive = true,
  285. [FromQuery] bool? enableImages = true,
  286. [FromQuery] bool enableTotalRecordCount = true)
  287. {
  288. var dtoOptions = new DtoOptions()
  289. .AddItemFields(fields)
  290. .AddClientFields(Request)
  291. .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
  292. User? user = null;
  293. BaseItem parentItem;
  294. if (!userId.Equals(Guid.Empty))
  295. {
  296. user = _userManager.GetUserById(userId);
  297. parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(parentId);
  298. }
  299. else
  300. {
  301. parentItem = string.IsNullOrEmpty(parentId) ? _libraryManager.RootFolder : _libraryManager.GetItemById(parentId);
  302. }
  303. IList<BaseItem> items;
  304. var excludeItemTypesArr = RequestHelpers.Split(excludeItemTypes, ',', true);
  305. var includeItemTypesArr = RequestHelpers.Split(includeItemTypes, ',', true);
  306. var mediaTypesArr = RequestHelpers.Split(mediaTypes, ',', true);
  307. var query = new InternalItemsQuery(user)
  308. {
  309. ExcludeItemTypes = excludeItemTypesArr,
  310. IncludeItemTypes = includeItemTypesArr,
  311. MediaTypes = mediaTypesArr,
  312. DtoOptions = dtoOptions
  313. };
  314. bool Filter(BaseItem i) => FilterItem(i, excludeItemTypesArr, includeItemTypesArr, mediaTypesArr);
  315. if (parentItem.IsFolder)
  316. {
  317. var folder = (Folder)parentItem;
  318. if (!userId.Equals(Guid.Empty))
  319. {
  320. items = recursive ? folder.GetRecursiveChildren(user, query).ToList() : folder.GetChildren(user, true).Where(Filter).ToList();
  321. }
  322. else
  323. {
  324. items = recursive ? folder.GetRecursiveChildren(Filter) : folder.Children.Where(Filter).ToList();
  325. }
  326. }
  327. else
  328. {
  329. items = new[] { parentItem }.Where(Filter).ToList();
  330. }
  331. var extractedItems = GetAllItems(items);
  332. var filteredItems = _libraryManager.Sort(extractedItems, user, RequestHelpers.GetOrderBy(sortBy, sortOrder));
  333. var ibnItemsArray = filteredItems.ToList();
  334. IEnumerable<BaseItem> ibnItems = ibnItemsArray;
  335. var result = new QueryResult<BaseItemDto> { TotalRecordCount = ibnItemsArray.Count };
  336. if (startIndex.HasValue || limit.HasValue)
  337. {
  338. if (startIndex.HasValue)
  339. {
  340. ibnItems = ibnItems.Skip(startIndex.Value);
  341. }
  342. if (limit.HasValue)
  343. {
  344. ibnItems = ibnItems.Take(limit.Value);
  345. }
  346. }
  347. var tuples = ibnItems.Select(i => new Tuple<BaseItem, List<BaseItem>>(i, new List<BaseItem>()));
  348. var dtos = tuples.Select(i => _dtoService.GetItemByNameDto(i.Item1, dtoOptions, i.Item2, user));
  349. result.Items = dtos.Where(i => i != null).ToArray();
  350. return result;
  351. }
  352. /// <summary>
  353. /// Gets a year.
  354. /// </summary>
  355. /// <param name="year">The year.</param>
  356. /// <param name="userId">Optional. Filter by user id, and attach user data.</param>
  357. /// <response code="200">Year returned.</response>
  358. /// <response code="404">Year not found.</response>
  359. /// <returns>
  360. /// An <see cref="OkResult"/> containing the year,
  361. /// or a <see cref="NotFoundResult"/> if year not found.
  362. /// </returns>
  363. [HttpGet("{year}")]
  364. [ProducesResponseType(StatusCodes.Status200OK)]
  365. [ProducesResponseType(StatusCodes.Status404NotFound)]
  366. public ActionResult<BaseItemDto> GetYear([FromRoute] int year, [FromQuery] Guid userId)
  367. {
  368. var item = _libraryManager.GetYear(year);
  369. if (item == null)
  370. {
  371. return NotFound();
  372. }
  373. var dtoOptions = new DtoOptions()
  374. .AddClientFields(Request);
  375. if (!userId.Equals(Guid.Empty))
  376. {
  377. var user = _userManager.GetUserById(userId);
  378. return _dtoService.GetBaseItemDto(item, dtoOptions, user);
  379. }
  380. return _dtoService.GetBaseItemDto(item, dtoOptions);
  381. }
  382. private bool FilterItem(BaseItem f, IReadOnlyCollection<string> excludeItemTypes, IReadOnlyCollection<string> includeItemTypes, IReadOnlyCollection<string> mediaTypes)
  383. {
  384. // Exclude item types
  385. if (excludeItemTypes.Count > 0 && excludeItemTypes.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase))
  386. {
  387. return false;
  388. }
  389. // Include item types
  390. if (includeItemTypes.Count > 0 && !includeItemTypes.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase))
  391. {
  392. return false;
  393. }
  394. // Include MediaTypes
  395. if (mediaTypes.Count > 0 && !mediaTypes.Contains(f.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
  396. {
  397. return false;
  398. }
  399. return true;
  400. }
  401. private IEnumerable<BaseItem> GetAllItems(IEnumerable<BaseItem> items)
  402. {
  403. return items
  404. .Select(i => i.ProductionYear ?? 0)
  405. .Where(i => i > 0)
  406. .Distinct()
  407. .Select(year => _libraryManager.GetYear(year));
  408. }
  409. }
  410. }