LiveTvProgram.cs 6.7 KB

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