LiveTvProgram.cs 8.7 KB

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