LiveTvProgram.cs 9.0 KB

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