LiveTvProgram.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Configuration;
  4. using MediaBrowser.Model.LiveTv;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Runtime.Serialization;
  8. using MediaBrowser.Model.Entities;
  9. using MediaBrowser.Model.Providers;
  10. namespace MediaBrowser.Controller.LiveTv
  11. {
  12. public class LiveTvProgram : BaseItem, IHasLookupInfo<LiveTvProgramLookupInfo>, IHasStartDate, IHasProgramAttributes
  13. {
  14. public override List<string> GetUserDataKeys()
  15. {
  16. var list = base.GetUserDataKeys();
  17. if (!IsSeries)
  18. {
  19. var key = this.GetProviderId(MetadataProviders.Imdb);
  20. if (!string.IsNullOrWhiteSpace(key))
  21. {
  22. list.Insert(0, key);
  23. }
  24. key = this.GetProviderId(MetadataProviders.Tmdb);
  25. if (!string.IsNullOrWhiteSpace(key))
  26. {
  27. list.Insert(0, key);
  28. }
  29. }
  30. else if (!string.IsNullOrWhiteSpace(EpisodeTitle))
  31. {
  32. var name = GetClientTypeName();
  33. list.Insert(0, name + "-" + Name + (EpisodeTitle ?? string.Empty));
  34. }
  35. return list;
  36. }
  37. [IgnoreDataMember]
  38. public override SourceType SourceType
  39. {
  40. get { return SourceType.LiveTV; }
  41. set { }
  42. }
  43. /// <summary>
  44. /// The start date of the program, in UTC.
  45. /// </summary>
  46. [IgnoreDataMember]
  47. public DateTime StartDate { get; set; }
  48. /// <summary>
  49. /// Gets or sets a value indicating whether this instance is repeat.
  50. /// </summary>
  51. /// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value>
  52. [IgnoreDataMember]
  53. public bool IsRepeat { get; set; }
  54. /// <summary>
  55. /// Gets or sets the episode title.
  56. /// </summary>
  57. /// <value>The episode title.</value>
  58. [IgnoreDataMember]
  59. public string EpisodeTitle { get; set; }
  60. /// <summary>
  61. /// Gets or sets a value indicating whether this instance is movie.
  62. /// </summary>
  63. /// <value><c>true</c> if this instance is movie; otherwise, <c>false</c>.</value>
  64. [IgnoreDataMember]
  65. public bool IsMovie { get; set; }
  66. /// <summary>
  67. /// Gets or sets a value indicating whether this instance is sports.
  68. /// </summary>
  69. /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
  70. [IgnoreDataMember]
  71. public bool IsSports { get; set; }
  72. /// <summary>
  73. /// Gets or sets a value indicating whether this instance is series.
  74. /// </summary>
  75. /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
  76. [IgnoreDataMember]
  77. public bool IsSeries { get; set; }
  78. /// <summary>
  79. /// Gets or sets a value indicating whether this instance is live.
  80. /// </summary>
  81. /// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
  82. [IgnoreDataMember]
  83. public bool IsLive { get; set; }
  84. /// <summary>
  85. /// Gets or sets a value indicating whether this instance is news.
  86. /// </summary>
  87. /// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
  88. [IgnoreDataMember]
  89. public bool IsNews { get; set; }
  90. /// <summary>
  91. /// Gets or sets a value indicating whether this instance is kids.
  92. /// </summary>
  93. /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
  94. [IgnoreDataMember]
  95. public bool IsKids { get; set; }
  96. /// <summary>
  97. /// Gets or sets a value indicating whether this instance is premiere.
  98. /// </summary>
  99. /// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
  100. [IgnoreDataMember]
  101. public bool IsPremiere { get; set; }
  102. /// <summary>
  103. /// Returns the folder containing the item.
  104. /// If the item is a folder, it returns the folder itself
  105. /// </summary>
  106. /// <value>The containing folder path.</value>
  107. [IgnoreDataMember]
  108. public override string ContainingFolderPath
  109. {
  110. get
  111. {
  112. return Path;
  113. }
  114. }
  115. /// <summary>
  116. /// Gets a value indicating whether this instance is owned item.
  117. /// </summary>
  118. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  119. [IgnoreDataMember]
  120. public override bool IsOwnedItem
  121. {
  122. get
  123. {
  124. return false;
  125. }
  126. }
  127. //[IgnoreDataMember]
  128. //public override string MediaType
  129. //{
  130. // get
  131. // {
  132. // return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
  133. // }
  134. //}
  135. [IgnoreDataMember]
  136. public bool IsAiring
  137. {
  138. get
  139. {
  140. var now = DateTime.UtcNow;
  141. return now >= StartDate && now < EndDate;
  142. }
  143. }
  144. [IgnoreDataMember]
  145. public bool HasAired
  146. {
  147. get
  148. {
  149. var now = DateTime.UtcNow;
  150. return now >= EndDate;
  151. }
  152. }
  153. public override string GetClientTypeName()
  154. {
  155. return "Program";
  156. }
  157. public override UnratedItem GetBlockUnratedType()
  158. {
  159. return UnratedItem.LiveTvProgram;
  160. }
  161. protected override string GetInternalMetadataPath(string basePath)
  162. {
  163. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"));
  164. }
  165. public override bool CanDelete()
  166. {
  167. return false;
  168. }
  169. public override bool IsInternetMetadataEnabled()
  170. {
  171. if (IsMovie)
  172. {
  173. var options = (LiveTvOptions)ConfigurationManager.GetConfiguration("livetv");
  174. return options.EnableMovieProviders;
  175. }
  176. return false;
  177. }
  178. public LiveTvProgramLookupInfo GetLookupInfo()
  179. {
  180. var info = GetItemLookupInfo<LiveTvProgramLookupInfo>();
  181. info.IsMovie = IsMovie;
  182. return info;
  183. }
  184. [IgnoreDataMember]
  185. public override bool SupportsPeople
  186. {
  187. get
  188. {
  189. // Optimization
  190. if (IsNews || IsSports)
  191. {
  192. return false;
  193. }
  194. return base.SupportsPeople;
  195. }
  196. }
  197. [IgnoreDataMember]
  198. public override bool SupportsAncestors
  199. {
  200. get
  201. {
  202. return false;
  203. }
  204. }
  205. public override List<ExternalUrl> GetRelatedUrls()
  206. {
  207. var list = base.GetRelatedUrls();
  208. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  209. if (!string.IsNullOrWhiteSpace(imdbId))
  210. {
  211. if (IsMovie)
  212. {
  213. list.Add(new ExternalUrl
  214. {
  215. Name = "Trakt",
  216. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  217. });
  218. }
  219. }
  220. return list;
  221. }
  222. }
  223. }