LiveTvProgram.cs 7.1 KB

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