InternalItemsQuery.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. #pragma warning disable CA1044, CA1819, CA2227, CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Jellyfin.Data;
  6. using Jellyfin.Data.Enums;
  7. using Jellyfin.Database.Implementations.Entities;
  8. using Jellyfin.Database.Implementations.Enums;
  9. using MediaBrowser.Controller.Dto;
  10. using MediaBrowser.Model.Entities;
  11. namespace MediaBrowser.Controller.Entities
  12. {
  13. public class InternalItemsQuery
  14. {
  15. public InternalItemsQuery()
  16. {
  17. AlbumArtistIds = Array.Empty<Guid>();
  18. AlbumIds = Array.Empty<Guid>();
  19. AncestorIds = Array.Empty<Guid>();
  20. ArtistIds = Array.Empty<Guid>();
  21. BlockUnratedItems = Array.Empty<UnratedItem>();
  22. BoxSetLibraryFolders = Array.Empty<Guid>();
  23. ChannelIds = Array.Empty<Guid>();
  24. ContributingArtistIds = Array.Empty<Guid>();
  25. DtoOptions = new DtoOptions();
  26. EnableTotalRecordCount = true;
  27. ExcludeArtistIds = Array.Empty<Guid>();
  28. ExcludeInheritedTags = Array.Empty<string>();
  29. IncludeInheritedTags = Array.Empty<string>();
  30. ExcludeItemIds = Array.Empty<Guid>();
  31. ExcludeItemTypes = Array.Empty<BaseItemKind>();
  32. ExcludeTags = Array.Empty<string>();
  33. GenreIds = Array.Empty<Guid>();
  34. Genres = Array.Empty<string>();
  35. GroupByPresentationUniqueKey = true;
  36. ImageTypes = Array.Empty<ImageType>();
  37. IncludeItemTypes = Array.Empty<BaseItemKind>();
  38. ItemIds = Array.Empty<Guid>();
  39. MediaTypes = Array.Empty<MediaType>();
  40. OfficialRatings = Array.Empty<string>();
  41. OrderBy = Array.Empty<(ItemSortBy, SortOrder)>();
  42. PersonIds = Array.Empty<Guid>();
  43. PersonTypes = Array.Empty<string>();
  44. PresetViews = Array.Empty<CollectionType?>();
  45. SeriesStatuses = Array.Empty<SeriesStatus>();
  46. SourceTypes = Array.Empty<SourceType>();
  47. StudioIds = Array.Empty<Guid>();
  48. Tags = Array.Empty<string>();
  49. TopParentIds = Array.Empty<Guid>();
  50. TrailerTypes = Array.Empty<TrailerType>();
  51. VideoTypes = Array.Empty<VideoType>();
  52. Years = Array.Empty<int>();
  53. SkipDeserialization = false;
  54. }
  55. public InternalItemsQuery(User? user)
  56. : this()
  57. {
  58. if (user is not null)
  59. {
  60. SetUser(user);
  61. }
  62. }
  63. public bool Recursive { get; set; }
  64. public int? StartIndex { get; set; }
  65. public int? Limit { get; set; }
  66. public User? User { get; set; }
  67. public bool? IsFolder { get; set; }
  68. public bool? IsFavorite { get; set; }
  69. public bool? IsFavoriteOrLiked { get; set; }
  70. public bool? IsLiked { get; set; }
  71. public bool? IsPlayed { get; set; }
  72. public bool? IsResumable { get; set; }
  73. public bool? IncludeItemsByName { get; set; }
  74. public MediaType[] MediaTypes { get; set; }
  75. public BaseItemKind[] IncludeItemTypes { get; set; }
  76. public BaseItemKind[] ExcludeItemTypes { get; set; }
  77. public string[] ExcludeTags { get; set; }
  78. public string[] ExcludeInheritedTags { get; set; }
  79. public string[] IncludeInheritedTags { get; set; }
  80. public IReadOnlyList<string> Genres { get; set; }
  81. public bool? IsSpecialSeason { get; set; }
  82. public bool? IsMissing { get; set; }
  83. public bool? IsUnaired { get; set; }
  84. public bool? CollapseBoxSetItems { get; set; }
  85. public string? NameStartsWithOrGreater { get; set; }
  86. public string? NameStartsWith { get; set; }
  87. public string? NameLessThan { get; set; }
  88. public string? NameContains { get; set; }
  89. public string? MinSortName { get; set; }
  90. public string? PresentationUniqueKey { get; set; }
  91. public string? Path { get; set; }
  92. public string? Name { get; set; }
  93. public string? Person { get; set; }
  94. public Guid[] PersonIds { get; set; }
  95. public Guid[] ItemIds { get; set; }
  96. public Guid[] ExcludeItemIds { get; set; }
  97. public Guid? AdjacentTo { get; set; }
  98. public string[] PersonTypes { get; set; }
  99. public bool? Is3D { get; set; }
  100. public bool? IsHD { get; set; }
  101. public bool? IsLocked { get; set; }
  102. public bool? IsPlaceHolder { get; set; }
  103. public bool? HasImdbId { get; set; }
  104. public bool? HasOverview { get; set; }
  105. public bool? HasTmdbId { get; set; }
  106. public bool? HasOfficialRating { get; set; }
  107. public bool? HasTvdbId { get; set; }
  108. public bool? HasThemeSong { get; set; }
  109. public bool? HasThemeVideo { get; set; }
  110. public bool? HasSubtitles { get; set; }
  111. public bool? HasSpecialFeature { get; set; }
  112. public bool? HasTrailer { get; set; }
  113. public bool? HasParentalRating { get; set; }
  114. public Guid[] StudioIds { get; set; }
  115. public IReadOnlyList<Guid> GenreIds { get; set; }
  116. public ImageType[] ImageTypes { get; set; }
  117. public VideoType[] VideoTypes { get; set; }
  118. public UnratedItem[] BlockUnratedItems { get; set; }
  119. public int[] Years { get; set; }
  120. public string[] Tags { get; set; }
  121. public string[] OfficialRatings { get; set; }
  122. public DateTime? MinPremiereDate { get; set; }
  123. public DateTime? MaxPremiereDate { get; set; }
  124. public DateTime? MinStartDate { get; set; }
  125. public DateTime? MaxStartDate { get; set; }
  126. public DateTime? MinEndDate { get; set; }
  127. public DateTime? MaxEndDate { get; set; }
  128. public bool? IsAiring { get; set; }
  129. public bool? IsMovie { get; set; }
  130. public bool? IsSports { get; set; }
  131. public bool? IsKids { get; set; }
  132. public bool? IsNews { get; set; }
  133. public bool? IsSeries { get; set; }
  134. public int? MinIndexNumber { get; set; }
  135. /// <summary>
  136. /// Gets or sets the minimum ParentIndexNumber and IndexNumber.
  137. /// </summary>
  138. /// <remarks>
  139. /// It produces this where clause:
  140. /// <para>(ParentIndexNumber = X and IndexNumber >= Y) or ParentIndexNumber > X.
  141. /// </para>
  142. /// </remarks>
  143. public (int ParentIndexNumber, int IndexNumber)? MinParentAndIndexNumber { get; set; }
  144. public int? AiredDuringSeason { get; set; }
  145. public double? MinCriticRating { get; set; }
  146. public double? MinCommunityRating { get; set; }
  147. public IReadOnlyList<Guid> ChannelIds { get; set; }
  148. public int? ParentIndexNumber { get; set; }
  149. public int? ParentIndexNumberNotEquals { get; set; }
  150. public int? IndexNumber { get; set; }
  151. public ParentalRatingScore? MinParentalRating { get; set; }
  152. public ParentalRatingScore? MaxParentalRating { get; set; }
  153. public bool? HasDeadParentId { get; set; }
  154. public bool? IsVirtualItem { get; set; }
  155. public Guid ParentId { get; set; }
  156. public BaseItemKind? ParentType { get; set; }
  157. public Guid[] AncestorIds { get; set; }
  158. public Guid[] TopParentIds { get; set; }
  159. public CollectionType?[] PresetViews { get; set; }
  160. public TrailerType[] TrailerTypes { get; set; }
  161. public SourceType[] SourceTypes { get; set; }
  162. public SeriesStatus[] SeriesStatuses { get; set; }
  163. public string? ExternalSeriesId { get; set; }
  164. public string? ExternalId { get; set; }
  165. public Guid[] AlbumIds { get; set; }
  166. public Guid[] ArtistIds { get; set; }
  167. public Guid[] ExcludeArtistIds { get; set; }
  168. public string? AncestorWithPresentationUniqueKey { get; set; }
  169. public string? SeriesPresentationUniqueKey { get; set; }
  170. public bool GroupByPresentationUniqueKey { get; set; }
  171. public bool GroupBySeriesPresentationUniqueKey { get; set; }
  172. public bool EnableTotalRecordCount { get; set; }
  173. public bool ForceDirect { get; set; }
  174. public Dictionary<string, string>? ExcludeProviderIds { get; set; }
  175. public bool EnableGroupByMetadataKey { get; set; }
  176. public bool? HasChapterImages { get; set; }
  177. public IReadOnlyList<(ItemSortBy OrderBy, SortOrder SortOrder)> OrderBy { get; set; }
  178. public DateTime? MinDateCreated { get; set; }
  179. public DateTime? MinDateLastSaved { get; set; }
  180. public DateTime? MinDateLastSavedForUser { get; set; }
  181. public DtoOptions DtoOptions { get; set; }
  182. public string? HasNoAudioTrackWithLanguage { get; set; }
  183. public string? HasNoInternalSubtitleTrackWithLanguage { get; set; }
  184. public string? HasNoExternalSubtitleTrackWithLanguage { get; set; }
  185. public string? HasNoSubtitleTrackWithLanguage { get; set; }
  186. public bool? IsDeadArtist { get; set; }
  187. public bool? IsDeadStudio { get; set; }
  188. public bool? IsDeadPerson { get; set; }
  189. /// <summary>
  190. /// Gets or sets a value indicating whether album sub-folders should be returned if they exist.
  191. /// </summary>
  192. public bool? DisplayAlbumFolders { get; set; }
  193. public BaseItem? Parent
  194. {
  195. set
  196. {
  197. if (value is null)
  198. {
  199. ParentId = Guid.Empty;
  200. ParentType = null;
  201. }
  202. else
  203. {
  204. ParentId = value.Id;
  205. ParentType = value.GetBaseItemKind();
  206. }
  207. }
  208. }
  209. public Dictionary<string, string>? HasAnyProviderId { get; set; }
  210. public Guid[] AlbumArtistIds { get; set; }
  211. public Guid[] BoxSetLibraryFolders { get; set; }
  212. public Guid[] ContributingArtistIds { get; set; }
  213. public bool? HasAired { get; set; }
  214. public bool? HasOwnerId { get; set; }
  215. public bool? Is4K { get; set; }
  216. public int? MaxHeight { get; set; }
  217. public int? MaxWidth { get; set; }
  218. public int? MinHeight { get; set; }
  219. public int? MinWidth { get; set; }
  220. public string? SearchTerm { get; set; }
  221. public string? SeriesTimerId { get; set; }
  222. public bool SkipDeserialization { get; set; }
  223. public void SetUser(User user)
  224. {
  225. var maxRating = user.MaxParentalRatingScore;
  226. if (maxRating.HasValue)
  227. {
  228. MaxParentalRating = new(maxRating.Value, user.MaxParentalRatingSubScore);
  229. }
  230. var other = UnratedItem.Other.ToString();
  231. BlockUnratedItems = user.GetPreference(PreferenceKind.BlockUnratedItems)
  232. .Where(i => i != other)
  233. .Select(e => Enum.Parse<UnratedItem>(e, true)).ToArray();
  234. ExcludeInheritedTags = user.GetPreference(PreferenceKind.BlockedTags);
  235. IncludeInheritedTags = user.GetPreference(PreferenceKind.AllowedTags);
  236. User = user;
  237. }
  238. }
  239. }