LiveTvProgram.cs 9.0 KB

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