LiveTvProgram.cs 8.2 KB

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