LiveTvProgram.cs 7.7 KB

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