LiveTvProgram.cs 9.0 KB

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