LiveTvProgram.cs 7.5 KB

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