LiveTvProgram.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. public override double? GetDefaultPrimaryImageAspectRatio()
  45. {
  46. if (IsMovie)
  47. {
  48. double value = 2;
  49. value /= 3;
  50. return value;
  51. }
  52. return null;
  53. }
  54. [IgnoreDataMember]
  55. public override SourceType SourceType
  56. {
  57. get { return SourceType.LiveTV; }
  58. set { }
  59. }
  60. /// <summary>
  61. /// The start date of the program, in UTC.
  62. /// </summary>
  63. [IgnoreDataMember]
  64. public DateTime StartDate { get; set; }
  65. /// <summary>
  66. /// Gets or sets a value indicating whether this instance is repeat.
  67. /// </summary>
  68. /// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value>
  69. [IgnoreDataMember]
  70. public bool IsRepeat { get; set; }
  71. /// <summary>
  72. /// Gets or sets the episode title.
  73. /// </summary>
  74. /// <value>The episode title.</value>
  75. [IgnoreDataMember]
  76. public string EpisodeTitle { get; set; }
  77. /// <summary>
  78. /// Gets or sets a value indicating whether this instance is movie.
  79. /// </summary>
  80. /// <value><c>true</c> if this instance is movie; otherwise, <c>false</c>.</value>
  81. [IgnoreDataMember]
  82. public bool IsMovie { get; set; }
  83. /// <summary>
  84. /// Gets or sets a value indicating whether this instance is sports.
  85. /// </summary>
  86. /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
  87. [IgnoreDataMember]
  88. public bool IsSports { get; set; }
  89. /// <summary>
  90. /// Gets or sets a value indicating whether this instance is series.
  91. /// </summary>
  92. /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
  93. [IgnoreDataMember]
  94. public bool IsSeries { get; set; }
  95. /// <summary>
  96. /// Gets or sets a value indicating whether this instance is live.
  97. /// </summary>
  98. /// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
  99. [IgnoreDataMember]
  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. [IgnoreDataMember]
  106. public bool IsNews { get; set; }
  107. /// <summary>
  108. /// Gets or sets a value indicating whether this instance is kids.
  109. /// </summary>
  110. /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
  111. [IgnoreDataMember]
  112. public bool IsKids { get; set; }
  113. /// <summary>
  114. /// Gets or sets a value indicating whether this instance is premiere.
  115. /// </summary>
  116. /// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
  117. [IgnoreDataMember]
  118. public bool IsPremiere { get; set; }
  119. /// <summary>
  120. /// Returns the folder containing the item.
  121. /// If the item is a folder, it returns the folder itself
  122. /// </summary>
  123. /// <value>The containing folder path.</value>
  124. [IgnoreDataMember]
  125. public override string ContainingFolderPath
  126. {
  127. get
  128. {
  129. return Path;
  130. }
  131. }
  132. /// <summary>
  133. /// Gets a value indicating whether this instance is owned item.
  134. /// </summary>
  135. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  136. [IgnoreDataMember]
  137. public override bool IsOwnedItem
  138. {
  139. get
  140. {
  141. return false;
  142. }
  143. }
  144. //[IgnoreDataMember]
  145. //public override string MediaType
  146. //{
  147. // get
  148. // {
  149. // return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
  150. // }
  151. //}
  152. [IgnoreDataMember]
  153. public bool IsAiring
  154. {
  155. get
  156. {
  157. var now = DateTime.UtcNow;
  158. return now >= StartDate && now < EndDate;
  159. }
  160. }
  161. [IgnoreDataMember]
  162. public bool HasAired
  163. {
  164. get
  165. {
  166. var now = DateTime.UtcNow;
  167. return now >= EndDate;
  168. }
  169. }
  170. public override string GetClientTypeName()
  171. {
  172. return "Program";
  173. }
  174. public override UnratedItem GetBlockUnratedType()
  175. {
  176. return UnratedItem.LiveTvProgram;
  177. }
  178. protected override string GetInternalMetadataPath(string basePath)
  179. {
  180. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"));
  181. }
  182. public override bool CanDelete()
  183. {
  184. return false;
  185. }
  186. public override bool IsInternetMetadataEnabled()
  187. {
  188. if (IsMovie)
  189. {
  190. var options = (LiveTvOptions)ConfigurationManager.GetConfiguration("livetv");
  191. return options.EnableMovieProviders;
  192. }
  193. return false;
  194. }
  195. public LiveTvProgramLookupInfo GetLookupInfo()
  196. {
  197. var info = GetItemLookupInfo<LiveTvProgramLookupInfo>();
  198. info.IsMovie = IsMovie;
  199. return info;
  200. }
  201. [IgnoreDataMember]
  202. public override bool SupportsPeople
  203. {
  204. get
  205. {
  206. // Optimization
  207. if (IsNews || IsSports)
  208. {
  209. return false;
  210. }
  211. return base.SupportsPeople;
  212. }
  213. }
  214. [IgnoreDataMember]
  215. public override bool SupportsAncestors
  216. {
  217. get
  218. {
  219. return false;
  220. }
  221. }
  222. private LiveTvOptions GetConfiguration()
  223. {
  224. return ConfigurationManager.GetConfiguration<LiveTvOptions>("livetv");
  225. }
  226. private ListingsProviderInfo GetListingsProviderInfo()
  227. {
  228. if (string.Equals(ServiceName, "Emby", StringComparison.OrdinalIgnoreCase))
  229. {
  230. var config = GetConfiguration();
  231. return config.ListingProviders.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.MoviePrefix));
  232. }
  233. return null;
  234. }
  235. protected override string GetNameForMetadataLookup()
  236. {
  237. var name = base.GetNameForMetadataLookup();
  238. var listings = GetListingsProviderInfo();
  239. if (listings != null)
  240. {
  241. if (!string.IsNullOrWhiteSpace(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringComparison.OrdinalIgnoreCase))
  242. {
  243. name = name.Substring(listings.MoviePrefix.Length).Trim();
  244. }
  245. }
  246. return name;
  247. }
  248. public override List<ExternalUrl> GetRelatedUrls()
  249. {
  250. var list = base.GetRelatedUrls();
  251. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  252. if (!string.IsNullOrWhiteSpace(imdbId))
  253. {
  254. if (IsMovie)
  255. {
  256. list.Add(new ExternalUrl
  257. {
  258. Name = "Trakt",
  259. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  260. });
  261. }
  262. }
  263. return list;
  264. }
  265. }
  266. }