LiveTvProgram.cs 9.1 KB

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