LiveTvProgram.cs 6.9 KB

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