LiveTvProgram.cs 9.0 KB

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