LiveTvProgram.cs 9.9 KB

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