LiveTvProgram.cs 7.9 KB

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