BaseItemsRequest.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 : IHasItemFields
  10. {
  11. /// <summary>
  12. /// Skips over a given number of items within the results. Use for paging.
  13. /// </summary>
  14. /// <value>The start index.</value>
  15. [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")]
  16. public int? StartIndex { get; set; }
  17. /// <summary>
  18. /// The maximum number of items to return
  19. /// </summary>
  20. /// <value>The limit.</value>
  21. [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
  22. public int? Limit { get; set; }
  23. /// <summary>
  24. /// Whether or not to perform the query recursively
  25. /// </summary>
  26. /// <value><c>true</c> if recursive; otherwise, <c>false</c>.</value>
  27. [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")]
  28. public bool Recursive { get; set; }
  29. /// <summary>
  30. /// Gets or sets the sort order.
  31. /// </summary>
  32. /// <value>The sort order.</value>
  33. [ApiMember(Name = "SortOrder", Description = "Sort Order - Ascending,Descending", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
  34. public SortOrder? SortOrder { get; set; }
  35. /// <summary>
  36. /// Specify this to localize the search to a specific item or folder. Omit to use the root.
  37. /// </summary>
  38. /// <value>The parent id.</value>
  39. [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")]
  40. public string ParentId { get; set; }
  41. /// <summary>
  42. /// Fields to return within the items, in addition to basic information
  43. /// </summary>
  44. /// <value>The fields.</value>
  45. [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)]
  46. public string Fields { get; set; }
  47. /// <summary>
  48. /// Gets or sets the exclude item types.
  49. /// </summary>
  50. /// <value>The exclude item types.</value>
  51. [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)]
  52. public string ExcludeItemTypes { get; set; }
  53. /// <summary>
  54. /// Gets or sets the include item types.
  55. /// </summary>
  56. /// <value>The include item types.</value>
  57. [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)]
  58. public string IncludeItemTypes { get; set; }
  59. /// <summary>
  60. /// Filters to apply to the results
  61. /// </summary>
  62. /// <value>The filters.</value>
  63. [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)]
  64. public string Filters { get; set; }
  65. /// <summary>
  66. /// Gets or sets the media types.
  67. /// </summary>
  68. /// <value>The media types.</value>
  69. [ApiMember(Name = "MediaTypes", Description = "Optional filter by MediaType. Allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
  70. public string MediaTypes { get; set; }
  71. /// <summary>
  72. /// Gets or sets the image types.
  73. /// </summary>
  74. /// <value>The image types.</value>
  75. [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)]
  76. public string ImageTypes { get; set; }
  77. /// <summary>
  78. /// What to sort the results by
  79. /// </summary>
  80. /// <value>The sort by.</value>
  81. [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)]
  82. public string SortBy { get; set; }
  83. [ApiMember(Name = "IsPlayed", Description = "Optional filter by items that are played, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
  84. public bool? IsPlayed { get; set; }
  85. /// <summary>
  86. /// Limit results to items containing specific genres
  87. /// </summary>
  88. /// <value>The genres.</value>
  89. [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)]
  90. public string Genres { get; set; }
  91. [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)]
  92. public string OfficialRatings { get; set; }
  93. [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)]
  94. public string Tags { get; set; }
  95. /// <summary>
  96. /// Limit results to items containing specific years
  97. /// </summary>
  98. /// <value>The years.</value>
  99. [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)]
  100. public string Years { get; set; }
  101. public string[] GetGenres()
  102. {
  103. return (Genres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  104. }
  105. public string[] GetTags()
  106. {
  107. return (Tags ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  108. }
  109. public string[] GetOfficialRatings()
  110. {
  111. return (OfficialRatings ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  112. }
  113. public string[] GetMediaTypes()
  114. {
  115. return (MediaTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  116. }
  117. public string[] GetIncludeItemTypes()
  118. {
  119. return (IncludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  120. }
  121. public string[] GetExcludeItemTypes()
  122. {
  123. return (ExcludeItemTypes ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  124. }
  125. public int[] GetYears()
  126. {
  127. return (Years ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  128. }
  129. /// <summary>
  130. /// Gets the filters.
  131. /// </summary>
  132. /// <returns>IEnumerable{ItemFilter}.</returns>
  133. public IEnumerable<ItemFilter> GetFilters()
  134. {
  135. var val = Filters;
  136. if (string.IsNullOrEmpty(val))
  137. {
  138. return new ItemFilter[] { };
  139. }
  140. return val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
  141. }
  142. /// <summary>
  143. /// Gets the image types.
  144. /// </summary>
  145. /// <returns>IEnumerable{ImageType}.</returns>
  146. public IEnumerable<ImageType> GetImageTypes()
  147. {
  148. var val = ImageTypes;
  149. if (string.IsNullOrEmpty(val))
  150. {
  151. return new ImageType[] { };
  152. }
  153. return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true));
  154. }
  155. /// <summary>
  156. /// Gets the order by.
  157. /// </summary>
  158. /// <returns>IEnumerable{ItemSortBy}.</returns>
  159. public string[] GetOrderBy()
  160. {
  161. var val = SortBy;
  162. if (string.IsNullOrEmpty(val))
  163. {
  164. return new string[] { };
  165. }
  166. return val.Split(',');
  167. }
  168. }
  169. }