BaseItemsRequest.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using MediaBrowser.Model.Entities;
  2. using MediaBrowser.Model.Querying;
  3. using ServiceStack;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace MediaBrowser.Api.UserLibrary
  8. {
  9. public abstract class BaseItemsRequest : IHasDtoOptions
  10. {
  11. protected BaseItemsRequest()
  12. {
  13. EnableImages = true;
  14. }
  15. /// <summary>
  16. /// Skips over a given number of items within the results. Use for paging.
  17. /// </summary>
  18. /// <value>The start index.</value>
  19. [ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  20. public int? StartIndex { get; set; }
  21. /// <summary>
  22. /// The maximum number of items to return
  23. /// </summary>
  24. /// <value>The limit.</value>
  25. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  26. public int? Limit { get; set; }
  27. /// <summary>
  28. /// Whether or not to perform the query recursively
  29. /// </summary>
  30. /// <value><c>true</c> if recursive; otherwise, <c>false</c>.</value>
  31. [ApiMember(Name = "Recursive", Description = "When searching within folders, this determines whether or not the search will be recursive. true/false", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  32. public bool Recursive { get; set; }
  33. /// <summary>
  34. /// Gets or sets the sort order.
  35. /// </summary>
  36. /// <value>The sort order.</value>
  37. [ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  38. public SortOrder? SortOrder { get; set; }
  39. /// <summary>
  40. /// Specify this to localize the search to a specific item or folder. Omit to use the root.
  41. /// </summary>
  42. /// <value>The parent id.</value>
  43. [ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  44. public string ParentId { get; set; }
  45. /// <summary>
  46. /// Fields to return within the items, in addition to basic information
  47. /// </summary>
  48. /// <value>The fields.</value>
  49. [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  50. public string Fields { get; set; }
  51. /// <summary>
  52. /// Gets or sets the exclude item types.
  53. /// </summary>
  54. /// <value>The exclude item types.</value>
  55. [ApiMember(Name = "ExcludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  56. public string ExcludeItemTypes { get; set; }
  57. /// <summary>
  58. /// Gets or sets the include item types.
  59. /// </summary>
  60. /// <value>The include item types.</value>
  61. [ApiMember(Name = "IncludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  62. public string IncludeItemTypes { get; set; }
  63. /// <summary>
  64. /// Filters to apply to the results
  65. /// </summary>
  66. /// <value>The filters.</value>
  67. [ApiMember(Name = "Filters", Description = "Optional. Specify additional filters to apply. This allows multiple, comma delimeted. Options: IsFolder, IsNotFolder, IsUnplayed, IsPlayed, IsFavorite, IsResumable, Likes, Dislikes", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  68. public string Filters { get; set; }
  69. /// <summary>
  70. /// Gets or sets the media types.
  71. /// </summary>
  72. /// <value>The media types.</value>
  73. [ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  74. public string MediaTypes { get; set; }
  75. /// <summary>
  76. /// Gets or sets the image types.
  77. /// </summary>
  78. /// <value>The image types.</value>
  79. [ApiMember(Name = "ImageTypes", Description = "Optional. If specified, results will be filtered based on those containing image types. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  80. public string ImageTypes { get; set; }
  81. /// <summary>
  82. /// What to sort the results by
  83. /// </summary>
  84. /// <value>The sort by.</value>
  85. [ApiMember(Name = "SortBy", Description = "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", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  86. public string SortBy { get; set; }
  87. [ApiMember(Name = "IsPlayed", Description = "Optional filter by items that are played, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  88. public bool? IsPlayed { get; set; }
  89. /// <summary>
  90. /// Limit results to items containing specific genres
  91. /// </summary>
  92. /// <value>The genres.</value>
  93. [ApiMember(Name = "Genres", Description = "Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  94. public string Genres { get; set; }
  95. [ApiMember(Name = "OfficialRatings", Description = "Optional. If specified, results will be filtered based on OfficialRating. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  96. public string OfficialRatings { get; set; }
  97. [ApiMember(Name = "Tags", Description = "Optional. If specified, results will be filtered based on tag. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  98. public string Tags { get; set; }
  99. /// <summary>
  100. /// Limit results to items containing specific years
  101. /// </summary>
  102. /// <value>The years.</value>
  103. [ApiMember(Name = "Years", Description = "Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  104. public string Years { get; set; }
  105. [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
  106. public bool? EnableImages { get; set; }
  107. [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  108. public int? ImageTypeLimit { get; set; }
  109. [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  110. public string EnableImageTypes { get; set; }
  111. public string[] GetGenres()
  112. {
  113. return (Genres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  114. }
  115. public string[] GetTags()
  116. {
  117. return (Tags ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  118. }
  119. public string[] GetOfficialRatings()
  120. {
  121. return (OfficialRatings ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  122. }
  123. public string[] GetMediaTypes()
  124. {
  125. return (MediaTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  126. }
  127. public string[] GetIncludeItemTypes()
  128. {
  129. return (IncludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  130. }
  131. public string[] GetExcludeItemTypes()
  132. {
  133. return (ExcludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  134. }
  135. public int[] GetYears()
  136. {
  137. return (Years ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  138. }
  139. /// <summary>
  140. /// Gets the filters.
  141. /// </summary>
  142. /// <returns>IEnumerable{ItemFilter}.</returns>
  143. public IEnumerable<ItemFilter> GetFilters()
  144. {
  145. var val = Filters;
  146. if (string.IsNullOrEmpty(val))
  147. {
  148. return new ItemFilter[] { };
  149. }
  150. return val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
  151. }
  152. /// <summary>
  153. /// Gets the image types.
  154. /// </summary>
  155. /// <returns>IEnumerable{ImageType}.</returns>
  156. public IEnumerable<ImageType> GetImageTypes()
  157. {
  158. var val = ImageTypes;
  159. if (string.IsNullOrEmpty(val))
  160. {
  161. return new ImageType[] { };
  162. }
  163. return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true));
  164. }
  165. /// <summary>
  166. /// Gets the order by.
  167. /// </summary>
  168. /// <returns>IEnumerable{ItemSortBy}.</returns>
  169. public string[] GetOrderBy()
  170. {
  171. var val = SortBy;
  172. if (string.IsNullOrEmpty(val))
  173. {
  174. return new string[] { };
  175. }
  176. return val.Split(',');
  177. }
  178. }
  179. }