LiveTvProgram.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Entities.Movies;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Model.Configuration;
  5. using MediaBrowser.Model.LiveTv;
  6. using MediaBrowser.Model.Users;
  7. using System;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. using MediaBrowser.Model.Entities;
  11. namespace MediaBrowser.Controller.LiveTv
  12. {
  13. public class LiveTvProgram : BaseItem, ILiveTvItem, IHasLookupInfo<LiveTvProgramLookupInfo>, IHasStartDate, IHasProgramAttributes
  14. {
  15. /// <summary>
  16. /// Gets the user data key.
  17. /// </summary>
  18. /// <returns>System.String.</returns>
  19. protected override string CreateUserDataKey()
  20. {
  21. if (IsMovie)
  22. {
  23. var key = Movie.GetMovieUserDataKey(this);
  24. if (!string.IsNullOrWhiteSpace(key))
  25. {
  26. return key;
  27. }
  28. }
  29. return GetClientTypeName() + "-" + Name;
  30. }
  31. /// <summary>
  32. /// Gets or sets the name.
  33. /// </summary>
  34. /// <value>The name.</value>
  35. [IgnoreDataMember]
  36. public string ServiceName { get; set; }
  37. /// <summary>
  38. /// The start date of the program, in UTC.
  39. /// </summary>
  40. [IgnoreDataMember]
  41. public DateTime StartDate { get; set; }
  42. /// <summary>
  43. /// Gets or sets a value indicating whether this instance is repeat.
  44. /// </summary>
  45. /// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value>
  46. [IgnoreDataMember]
  47. public bool IsRepeat { get; set; }
  48. /// <summary>
  49. /// Gets or sets the episode title.
  50. /// </summary>
  51. /// <value>The episode title.</value>
  52. [IgnoreDataMember]
  53. public string EpisodeTitle { get; set; }
  54. /// <summary>
  55. /// Gets or sets a value indicating whether this instance is movie.
  56. /// </summary>
  57. /// <value><c>true</c> if this instance is movie; otherwise, <c>false</c>.</value>
  58. [IgnoreDataMember]
  59. public bool IsMovie { get; set; }
  60. /// <summary>
  61. /// Gets or sets a value indicating whether this instance is sports.
  62. /// </summary>
  63. /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
  64. [IgnoreDataMember]
  65. public bool IsSports { get; set; }
  66. /// <summary>
  67. /// Gets or sets a value indicating whether this instance is series.
  68. /// </summary>
  69. /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
  70. [IgnoreDataMember]
  71. public bool IsSeries { get; set; }
  72. /// <summary>
  73. /// Gets or sets a value indicating whether this instance is live.
  74. /// </summary>
  75. /// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
  76. [IgnoreDataMember]
  77. public bool IsLive { get; set; }
  78. /// <summary>
  79. /// Gets or sets a value indicating whether this instance is news.
  80. /// </summary>
  81. /// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
  82. [IgnoreDataMember]
  83. public bool IsNews { get; set; }
  84. /// <summary>
  85. /// Gets or sets a value indicating whether this instance is kids.
  86. /// </summary>
  87. /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
  88. [IgnoreDataMember]
  89. public bool IsKids { get; set; }
  90. /// <summary>
  91. /// Gets or sets a value indicating whether this instance is premiere.
  92. /// </summary>
  93. /// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
  94. [IgnoreDataMember]
  95. public bool IsPremiere { get; set; }
  96. /// <summary>
  97. /// Returns the folder containing the item.
  98. /// If the item is a folder, it returns the folder itself
  99. /// </summary>
  100. /// <value>The containing folder path.</value>
  101. [IgnoreDataMember]
  102. public override string ContainingFolderPath
  103. {
  104. get
  105. {
  106. return Path;
  107. }
  108. }
  109. /// <summary>
  110. /// Gets a value indicating whether this instance is owned item.
  111. /// </summary>
  112. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  113. [IgnoreDataMember]
  114. public override bool IsOwnedItem
  115. {
  116. get
  117. {
  118. return false;
  119. }
  120. }
  121. //[IgnoreDataMember]
  122. //public override string MediaType
  123. //{
  124. // get
  125. // {
  126. // return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
  127. // }
  128. //}
  129. [IgnoreDataMember]
  130. public bool IsAiring
  131. {
  132. get
  133. {
  134. var now = DateTime.UtcNow;
  135. return now >= StartDate && now < EndDate;
  136. }
  137. }
  138. [IgnoreDataMember]
  139. public bool HasAired
  140. {
  141. get
  142. {
  143. var now = DateTime.UtcNow;
  144. return now >= EndDate;
  145. }
  146. }
  147. public override string GetClientTypeName()
  148. {
  149. return "Program";
  150. }
  151. protected override bool GetBlockUnratedValue(UserPolicy config)
  152. {
  153. return config.BlockUnratedItems.Contains(UnratedItem.LiveTvProgram);
  154. }
  155. protected override string GetInternalMetadataPath(string basePath)
  156. {
  157. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"));
  158. }
  159. public override bool CanDelete()
  160. {
  161. return false;
  162. }
  163. public override bool IsInternetMetadataEnabled()
  164. {
  165. if (IsMovie)
  166. {
  167. var options = (LiveTvOptions)ConfigurationManager.GetConfiguration("livetv");
  168. return options.EnableMovieProviders;
  169. }
  170. return false;
  171. }
  172. public LiveTvProgramLookupInfo GetLookupInfo()
  173. {
  174. var info = GetItemLookupInfo<LiveTvProgramLookupInfo>();
  175. info.IsMovie = IsMovie;
  176. return info;
  177. }
  178. [IgnoreDataMember]
  179. public override bool SupportsPeople
  180. {
  181. get
  182. {
  183. // Optimization
  184. if (IsNews || IsSports)
  185. {
  186. return false;
  187. }
  188. return base.SupportsPeople;
  189. }
  190. }
  191. [IgnoreDataMember]
  192. public override bool SupportsAncestors
  193. {
  194. get
  195. {
  196. return false;
  197. }
  198. }
  199. }
  200. }