LiveTvProgram.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Common.Configuration;
  5. using MediaBrowser.Controller.Entities;
  6. using MediaBrowser.Controller.Providers;
  7. using MediaBrowser.Model.Configuration;
  8. using MediaBrowser.Model.Entities;
  9. using MediaBrowser.Model.LiveTv;
  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 => SourceType.LiveTV;
  58. /// <summary>
  59. /// The start date of the program, in UTC.
  60. /// </summary>
  61. [IgnoreDataMember]
  62. public DateTime StartDate { get; set; }
  63. /// <summary>
  64. /// Gets or sets a value indicating whether this instance is repeat.
  65. /// </summary>
  66. /// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value>
  67. [IgnoreDataMember]
  68. public bool IsRepeat { get; set; }
  69. /// <summary>
  70. /// Gets or sets the episode title.
  71. /// </summary>
  72. /// <value>The episode title.</value>
  73. [IgnoreDataMember]
  74. public string EpisodeTitle { get; set; }
  75. [IgnoreDataMember]
  76. public string ShowId { 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 => Tags.Contains("Sports", StringComparer.OrdinalIgnoreCase);
  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 => Tags.Contains("Live", StringComparer.OrdinalIgnoreCase);
  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 => Tags.Contains("News", StringComparer.OrdinalIgnoreCase);
  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 => Tags.Contains("Kids", StringComparer.OrdinalIgnoreCase);
  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 => Tags.Contains("Premiere", StringComparer.OrdinalIgnoreCase);
  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 => Path;
  126. //[IgnoreDataMember]
  127. //public override string MediaType
  128. //{
  129. // get
  130. // {
  131. // return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
  132. // }
  133. //}
  134. [IgnoreDataMember]
  135. public bool IsAiring
  136. {
  137. get
  138. {
  139. var now = DateTime.UtcNow;
  140. return now >= StartDate && now < EndDate;
  141. }
  142. }
  143. [IgnoreDataMember]
  144. public bool HasAired
  145. {
  146. get
  147. {
  148. var now = DateTime.UtcNow;
  149. return now >= EndDate;
  150. }
  151. }
  152. public override string GetClientTypeName()
  153. {
  154. return "Program";
  155. }
  156. public override UnratedItem GetBlockUnratedType()
  157. {
  158. return UnratedItem.LiveTvProgram;
  159. }
  160. protected override string GetInternalMetadataPath(string basePath)
  161. {
  162. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"));
  163. }
  164. public override bool CanDelete()
  165. {
  166. return false;
  167. }
  168. [IgnoreDataMember]
  169. public override bool SupportsPeople
  170. {
  171. get
  172. {
  173. // Optimization
  174. if (IsNews || IsSports)
  175. {
  176. return false;
  177. }
  178. return base.SupportsPeople;
  179. }
  180. }
  181. [IgnoreDataMember]
  182. public override bool SupportsAncestors => false;
  183. private LiveTvOptions GetConfiguration()
  184. {
  185. return ConfigurationManager.GetConfiguration<LiveTvOptions>("livetv");
  186. }
  187. private ListingsProviderInfo GetListingsProviderInfo()
  188. {
  189. if (string.Equals(ServiceName, "Emby", StringComparison.OrdinalIgnoreCase))
  190. {
  191. var config = GetConfiguration();
  192. return config.ListingProviders.FirstOrDefault(i => !string.IsNullOrEmpty(i.MoviePrefix));
  193. }
  194. return null;
  195. }
  196. protected override string GetNameForMetadataLookup()
  197. {
  198. var name = base.GetNameForMetadataLookup();
  199. var listings = GetListingsProviderInfo();
  200. if (listings != null)
  201. {
  202. if (!string.IsNullOrEmpty(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringComparison.OrdinalIgnoreCase))
  203. {
  204. name = name.Substring(listings.MoviePrefix.Length).Trim();
  205. }
  206. }
  207. return name;
  208. }
  209. public override List<ExternalUrl> GetRelatedUrls()
  210. {
  211. var list = base.GetRelatedUrls();
  212. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  213. if (!string.IsNullOrEmpty(imdbId))
  214. {
  215. if (IsMovie)
  216. {
  217. list.Add(new ExternalUrl
  218. {
  219. Name = "Trakt",
  220. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  221. });
  222. }
  223. }
  224. return list;
  225. }
  226. public string SeriesName { get; set; }
  227. }
  228. }