LiveTvProgram.cs 7.1 KB

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