TrailersController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using Jellyfin.Api.Constants;
  3. using MediaBrowser.Controller.Dto;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Model.Dto;
  6. using MediaBrowser.Model.Globalization;
  7. using MediaBrowser.Model.Querying;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Http;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.Extensions.Logging;
  12. namespace Jellyfin.Api.Controllers
  13. {
  14. /// <summary>
  15. /// The trailers controller.
  16. /// </summary>
  17. [Authorize(Policy = Policies.DefaultAuthorization)]
  18. public class TrailersController : BaseJellyfinApiController
  19. {
  20. private readonly IUserManager _userManager;
  21. private readonly ILibraryManager _libraryManager;
  22. private readonly ILogger<ItemsController> _logger;
  23. private readonly IDtoService _dtoService;
  24. private readonly ILocalizationManager _localizationManager;
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref="TrailersController"/> class.
  27. /// </summary>
  28. /// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
  29. /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
  30. /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
  31. /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
  32. /// <param name="localizationManager">Instance of the <see cref="ILocalizationManager"/> interface.</param>
  33. public TrailersController(
  34. ILoggerFactory loggerFactory,
  35. IUserManager userManager,
  36. ILibraryManager libraryManager,
  37. IDtoService dtoService,
  38. ILocalizationManager localizationManager)
  39. {
  40. _userManager = userManager;
  41. _libraryManager = libraryManager;
  42. _dtoService = dtoService;
  43. _localizationManager = localizationManager;
  44. _logger = loggerFactory.CreateLogger<ItemsController>();
  45. }
  46. /// <summary>
  47. /// Finds movies and trailers similar to a given trailer.
  48. /// </summary>
  49. /// <param name="userId">The user id.</param>
  50. /// <param name="maxOfficialRating">Optional filter by maximum official rating (PG, PG-13, TV-MA, etc).</param>
  51. /// <param name="hasThemeSong">Optional filter by items with theme songs.</param>
  52. /// <param name="hasThemeVideo">Optional filter by items with theme videos.</param>
  53. /// <param name="hasSubtitles">Optional filter by items with subtitles.</param>
  54. /// <param name="hasSpecialFeature">Optional filter by items with special features.</param>
  55. /// <param name="hasTrailer">Optional filter by items with trailers.</param>
  56. /// <param name="adjacentTo">Optional. Return items that are siblings of a supplied item.</param>
  57. /// <param name="parentIndexNumber">Optional filter by parent index number.</param>
  58. /// <param name="hasParentalRating">Optional filter by items that have or do not have a parental rating.</param>
  59. /// <param name="isHd">Optional filter by items that are HD or not.</param>
  60. /// <param name="is4K">Optional filter by items that are 4K or not.</param>
  61. /// <param name="locationTypes">Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.</param>
  62. /// <param name="excludeLocationTypes">Optional. If specified, results will be filtered based on the LocationType. This allows multiple, comma delimeted.</param>
  63. /// <param name="isMissing">Optional filter by items that are missing episodes or not.</param>
  64. /// <param name="isUnaired">Optional filter by items that are unaired episodes or not.</param>
  65. /// <param name="minCommunityRating">Optional filter by minimum community rating.</param>
  66. /// <param name="minCriticRating">Optional filter by minimum critic rating.</param>
  67. /// <param name="minPremiereDate">Optional. The minimum premiere date. Format = ISO.</param>
  68. /// <param name="minDateLastSaved">Optional. The minimum last saved date. Format = ISO.</param>
  69. /// <param name="minDateLastSavedForUser">Optional. The minimum last saved date for the current user. Format = ISO.</param>
  70. /// <param name="maxPremiereDate">Optional. The maximum premiere date. Format = ISO.</param>
  71. /// <param name="hasOverview">Optional filter by items that have an overview or not.</param>
  72. /// <param name="hasImdbId">Optional filter by items that have an imdb id or not.</param>
  73. /// <param name="hasTmdbId">Optional filter by items that have a tmdb id or not.</param>
  74. /// <param name="hasTvdbId">Optional filter by items that have a tvdb id or not.</param>
  75. /// <param name="excludeItemIds">Optional. If specified, results will be filtered by exxcluding item ids. This allows multiple, comma delimeted.</param>
  76. /// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
  77. /// <param name="limit">Optional. The maximum number of records to return.</param>
  78. /// <param name="recursive">When searching within folders, this determines whether or not the search will be recursive. true/false.</param>
  79. /// <param name="searchTerm">Optional. Filter based on a search term.</param>
  80. /// <param name="sortOrder">Sort Order - Ascending,Descending.</param>
  81. /// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
  82. /// <param name="fields">Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines.</param>
  83. /// <param name="excludeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.</param>
  84. /// <param name="filters">Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes.</param>
  85. /// <param name="isFavorite">Optional filter by items that are marked as favorite, or not.</param>
  86. /// <param name="mediaTypes">Optional filter by MediaType. Allows multiple, comma delimited.</param>
  87. /// <param name="imageTypes">Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.</param>
  88. /// <param name="sortBy">Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, Budget, CommunityRating, CriticRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Revenue, Runtime.</param>
  89. /// <param name="isPlayed">Optional filter by items that are played, or not.</param>
  90. /// <param name="genres">Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.</param>
  91. /// <param name="officialRatings">Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimeted.</param>
  92. /// <param name="tags">Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimeted.</param>
  93. /// <param name="years">Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.</param>
  94. /// <param name="enableUserData">Optional, include user data.</param>
  95. /// <param name="imageTypeLimit">Optional, the max number of images to return, per image type.</param>
  96. /// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
  97. /// <param name="person">Optional. If specified, results will be filtered to include only those containing the specified person.</param>
  98. /// <param name="personIds">Optional. If specified, results will be filtered to include only those containing the specified person id.</param>
  99. /// <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>
  100. /// <param name="studios">Optional. If specified, results will be filtered based on studio. This allows multiple, pipe delimeted.</param>
  101. /// <param name="artists">Optional. If specified, results will be filtered based on artists. This allows multiple, pipe delimeted.</param>
  102. /// <param name="excludeArtistIds">Optional. If specified, results will be filtered based on artist id. This allows multiple, pipe delimeted.</param>
  103. /// <param name="artistIds">Optional. If specified, results will be filtered to include only those containing the specified artist id.</param>
  104. /// <param name="albumArtistIds">Optional. If specified, results will be filtered to include only those containing the specified album artist id.</param>
  105. /// <param name="contributingArtistIds">Optional. If specified, results will be filtered to include only those containing the specified contributing artist id.</param>
  106. /// <param name="albums">Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.</param>
  107. /// <param name="albumIds">Optional. If specified, results will be filtered based on album id. This allows multiple, pipe delimeted.</param>
  108. /// <param name="ids">Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.</param>
  109. /// <param name="videoTypes">Optional filter by VideoType (videofile, dvd, bluray, iso). Allows multiple, comma delimeted.</param>
  110. /// <param name="minOfficialRating">Optional filter by minimum official rating (PG, PG-13, TV-MA, etc).</param>
  111. /// <param name="isLocked">Optional filter by items that are locked.</param>
  112. /// <param name="isPlaceHolder">Optional filter by items that are placeholders.</param>
  113. /// <param name="hasOfficialRating">Optional filter by items that have official ratings.</param>
  114. /// <param name="collapseBoxSetItems">Whether or not to hide items behind their boxsets.</param>
  115. /// <param name="minWidth">Optional. Filter by the minimum width of the item.</param>
  116. /// <param name="minHeight">Optional. Filter by the minimum height of the item.</param>
  117. /// <param name="maxWidth">Optional. Filter by the maximum width of the item.</param>
  118. /// <param name="maxHeight">Optional. Filter by the maximum height of the item.</param>
  119. /// <param name="is3D">Optional filter by items that are 3D, or not.</param>
  120. /// <param name="seriesStatus">Optional filter by Series Status. Allows multiple, comma delimeted.</param>
  121. /// <param name="nameStartsWithOrGreater">Optional filter by items whose name is sorted equally or greater than a given input string.</param>
  122. /// <param name="nameStartsWith">Optional filter by items whose name is sorted equally than a given input string.</param>
  123. /// <param name="nameLessThan">Optional filter by items whose name is equally or lesser than a given input string.</param>
  124. /// <param name="studioIds">Optional. If specified, results will be filtered based on studio id. This allows multiple, pipe delimeted.</param>
  125. /// <param name="genreIds">Optional. If specified, results will be filtered based on genre id. This allows multiple, pipe delimeted.</param>
  126. /// <param name="enableTotalRecordCount">Optional. Enable the total record count.</param>
  127. /// <param name="enableImages">Optional, include image information in output.</param>
  128. /// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the trailers.</returns>
  129. [HttpGet("/Trailers")]
  130. [ProducesResponseType(StatusCodes.Status200OK)]
  131. public ActionResult<QueryResult<BaseItemDto>> GetTrailers(
  132. [FromQuery] Guid? userId,
  133. [FromQuery] string? maxOfficialRating,
  134. [FromQuery] bool? hasThemeSong,
  135. [FromQuery] bool? hasThemeVideo,
  136. [FromQuery] bool? hasSubtitles,
  137. [FromQuery] bool? hasSpecialFeature,
  138. [FromQuery] bool? hasTrailer,
  139. [FromQuery] string? adjacentTo,
  140. [FromQuery] int? parentIndexNumber,
  141. [FromQuery] bool? hasParentalRating,
  142. [FromQuery] bool? isHd,
  143. [FromQuery] bool? is4K,
  144. [FromQuery] string? locationTypes,
  145. [FromQuery] string? excludeLocationTypes,
  146. [FromQuery] bool? isMissing,
  147. [FromQuery] bool? isUnaired,
  148. [FromQuery] double? minCommunityRating,
  149. [FromQuery] double? minCriticRating,
  150. [FromQuery] DateTime? minPremiereDate,
  151. [FromQuery] DateTime? minDateLastSaved,
  152. [FromQuery] DateTime? minDateLastSavedForUser,
  153. [FromQuery] DateTime? maxPremiereDate,
  154. [FromQuery] bool? hasOverview,
  155. [FromQuery] bool? hasImdbId,
  156. [FromQuery] bool? hasTmdbId,
  157. [FromQuery] bool? hasTvdbId,
  158. [FromQuery] string? excludeItemIds,
  159. [FromQuery] int? startIndex,
  160. [FromQuery] int? limit,
  161. [FromQuery] bool? recursive,
  162. [FromQuery] string? searchTerm,
  163. [FromQuery] string? sortOrder,
  164. [FromQuery] string? parentId,
  165. [FromQuery] string? fields,
  166. [FromQuery] string? excludeItemTypes,
  167. [FromQuery] string? filters,
  168. [FromQuery] bool? isFavorite,
  169. [FromQuery] string? mediaTypes,
  170. [FromQuery] string? imageTypes,
  171. [FromQuery] string? sortBy,
  172. [FromQuery] bool? isPlayed,
  173. [FromQuery] string? genres,
  174. [FromQuery] string? officialRatings,
  175. [FromQuery] string? tags,
  176. [FromQuery] string? years,
  177. [FromQuery] bool? enableUserData,
  178. [FromQuery] int? imageTypeLimit,
  179. [FromQuery] string? enableImageTypes,
  180. [FromQuery] string? person,
  181. [FromQuery] string? personIds,
  182. [FromQuery] string? personTypes,
  183. [FromQuery] string? studios,
  184. [FromQuery] string? artists,
  185. [FromQuery] string? excludeArtistIds,
  186. [FromQuery] string? artistIds,
  187. [FromQuery] string? albumArtistIds,
  188. [FromQuery] string? contributingArtistIds,
  189. [FromQuery] string? albums,
  190. [FromQuery] string? albumIds,
  191. [FromQuery] string? ids,
  192. [FromQuery] string? videoTypes,
  193. [FromQuery] string? minOfficialRating,
  194. [FromQuery] bool? isLocked,
  195. [FromQuery] bool? isPlaceHolder,
  196. [FromQuery] bool? hasOfficialRating,
  197. [FromQuery] bool? collapseBoxSetItems,
  198. [FromQuery] int? minWidth,
  199. [FromQuery] int? minHeight,
  200. [FromQuery] int? maxWidth,
  201. [FromQuery] int? maxHeight,
  202. [FromQuery] bool? is3D,
  203. [FromQuery] string? seriesStatus,
  204. [FromQuery] string? nameStartsWithOrGreater,
  205. [FromQuery] string? nameStartsWith,
  206. [FromQuery] string? nameLessThan,
  207. [FromQuery] string? studioIds,
  208. [FromQuery] string? genreIds,
  209. [FromQuery] bool enableTotalRecordCount = true,
  210. [FromQuery] bool? enableImages = true)
  211. {
  212. var includeItemTypes = "Trailer";
  213. return new ItemsController(
  214. _userManager,
  215. _libraryManager,
  216. _localizationManager,
  217. _dtoService,
  218. _logger)
  219. .GetItems(
  220. userId,
  221. userId,
  222. maxOfficialRating,
  223. hasThemeSong,
  224. hasThemeVideo,
  225. hasSubtitles,
  226. hasSpecialFeature,
  227. hasTrailer,
  228. adjacentTo,
  229. parentIndexNumber,
  230. hasParentalRating,
  231. isHd,
  232. is4K,
  233. locationTypes,
  234. excludeLocationTypes,
  235. isMissing,
  236. isUnaired,
  237. minCommunityRating,
  238. minCriticRating,
  239. minPremiereDate,
  240. minDateLastSaved,
  241. minDateLastSavedForUser,
  242. maxPremiereDate,
  243. hasOverview,
  244. hasImdbId,
  245. hasTmdbId,
  246. hasTvdbId,
  247. excludeItemIds,
  248. startIndex,
  249. limit,
  250. recursive,
  251. searchTerm,
  252. sortOrder,
  253. parentId,
  254. fields,
  255. excludeItemTypes,
  256. includeItemTypes,
  257. filters,
  258. isFavorite,
  259. mediaTypes,
  260. imageTypes,
  261. sortBy,
  262. isPlayed,
  263. genres,
  264. officialRatings,
  265. tags,
  266. years,
  267. enableUserData,
  268. imageTypeLimit,
  269. enableImageTypes,
  270. person,
  271. personIds,
  272. personTypes,
  273. studios,
  274. artists,
  275. excludeArtistIds,
  276. artistIds,
  277. albumArtistIds,
  278. contributingArtistIds,
  279. albums,
  280. albumIds,
  281. ids,
  282. videoTypes,
  283. minOfficialRating,
  284. isLocked,
  285. isPlaceHolder,
  286. hasOfficialRating,
  287. collapseBoxSetItems,
  288. minWidth,
  289. minHeight,
  290. maxWidth,
  291. maxHeight,
  292. is3D,
  293. seriesStatus,
  294. nameStartsWithOrGreater,
  295. nameStartsWith,
  296. nameLessThan,
  297. studioIds,
  298. genreIds,
  299. enableTotalRecordCount,
  300. enableImages);
  301. }
  302. }
  303. }