LiveTvProgram.cs 6.7 KB

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