LiveTvProgram.cs 7.0 KB

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