LiveTvProgram.cs 9.4 KB

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