LiveTvProgram.cs 8.1 KB

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