LiveTvProgram.cs 6.9 KB

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