LiveTvProgram.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text.Json.Serialization;
  7. using Jellyfin.Data.Enums;
  8. using MediaBrowser.Common.Configuration;
  9. using MediaBrowser.Controller.Entities;
  10. using MediaBrowser.Controller.Providers;
  11. using MediaBrowser.Model.Entities;
  12. using MediaBrowser.Model.LiveTv;
  13. using MediaBrowser.Model.Providers;
  14. namespace MediaBrowser.Controller.LiveTv
  15. {
  16. public class LiveTvProgram : BaseItem, IHasLookupInfo<ItemLookupInfo>, IHasStartDate, IHasProgramAttributes
  17. {
  18. public LiveTvProgram()
  19. {
  20. IsVirtualItem = true;
  21. }
  22. public override List<string> GetUserDataKeys()
  23. {
  24. var list = base.GetUserDataKeys();
  25. if (!IsSeries)
  26. {
  27. var key = this.GetProviderId(MetadataProvider.Imdb);
  28. if (!string.IsNullOrEmpty(key))
  29. {
  30. list.Insert(0, key);
  31. }
  32. key = this.GetProviderId(MetadataProvider.Tmdb);
  33. if (!string.IsNullOrEmpty(key))
  34. {
  35. list.Insert(0, key);
  36. }
  37. }
  38. else if (!string.IsNullOrEmpty(EpisodeTitle))
  39. {
  40. var name = GetClientTypeName();
  41. list.Insert(0, name + "-" + Name + (EpisodeTitle ?? string.Empty));
  42. }
  43. return list;
  44. }
  45. private static string EmbyServiceName = "Emby";
  46. public override double GetDefaultPrimaryImageAspectRatio()
  47. {
  48. var serviceName = ServiceName;
  49. if (string.Equals(serviceName, EmbyServiceName, StringComparison.OrdinalIgnoreCase) || string.Equals(serviceName, "Next Pvr", StringComparison.OrdinalIgnoreCase))
  50. {
  51. return 2.0 / 3;
  52. }
  53. else
  54. {
  55. return 16.0 / 9;
  56. }
  57. }
  58. [JsonIgnore]
  59. public override SourceType SourceType => SourceType.LiveTV;
  60. /// <summary>
  61. /// The start date of the program, in UTC.
  62. /// </summary>
  63. [JsonIgnore]
  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. [JsonIgnore]
  70. public bool IsRepeat { get; set; }
  71. /// <summary>
  72. /// Gets or sets the episode title.
  73. /// </summary>
  74. /// <value>The episode title.</value>
  75. [JsonIgnore]
  76. public string EpisodeTitle { get; set; }
  77. [JsonIgnore]
  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. [JsonIgnore]
  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. [JsonIgnore]
  90. public bool IsSports => Tags.Contains("Sports", StringComparer.OrdinalIgnoreCase);
  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. [JsonIgnore]
  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. [JsonIgnore]
  102. public bool IsLive => Tags.Contains("Live", StringComparer.OrdinalIgnoreCase);
  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. [JsonIgnore]
  108. public bool IsNews => Tags.Contains("News", StringComparer.OrdinalIgnoreCase);
  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. [JsonIgnore]
  114. public bool IsKids => Tags.Contains("Kids", StringComparer.OrdinalIgnoreCase);
  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. [JsonIgnore]
  120. public bool IsPremiere => Tags.Contains("Premiere", StringComparer.OrdinalIgnoreCase);
  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. [JsonIgnore]
  127. public override string ContainingFolderPath => Path;
  128. //[JsonIgnore]
  129. // public override string MediaType
  130. //{
  131. // get
  132. // {
  133. // return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
  134. // }
  135. //}
  136. [JsonIgnore]
  137. public bool IsAiring
  138. {
  139. get
  140. {
  141. var now = DateTime.UtcNow;
  142. return now >= StartDate && now < EndDate;
  143. }
  144. }
  145. [JsonIgnore]
  146. public bool HasAired
  147. {
  148. get
  149. {
  150. var now = DateTime.UtcNow;
  151. return now >= EndDate;
  152. }
  153. }
  154. public override string GetClientTypeName()
  155. {
  156. return "Program";
  157. }
  158. public override UnratedItem GetBlockUnratedType()
  159. {
  160. return UnratedItem.LiveTvProgram;
  161. }
  162. protected override string GetInternalMetadataPath(string basePath)
  163. {
  164. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N", CultureInfo.InvariantCulture));
  165. }
  166. public override bool CanDelete()
  167. {
  168. return false;
  169. }
  170. [JsonIgnore]
  171. public override bool SupportsPeople
  172. {
  173. get
  174. {
  175. // Optimization
  176. if (IsNews || IsSports)
  177. {
  178. return false;
  179. }
  180. return base.SupportsPeople;
  181. }
  182. }
  183. [JsonIgnore]
  184. public override bool SupportsAncestors => false;
  185. private LiveTvOptions GetConfiguration()
  186. {
  187. return ConfigurationManager.GetConfiguration<LiveTvOptions>("livetv");
  188. }
  189. private ListingsProviderInfo GetListingsProviderInfo()
  190. {
  191. if (string.Equals(ServiceName, "Emby", StringComparison.OrdinalIgnoreCase))
  192. {
  193. var config = GetConfiguration();
  194. return config.ListingProviders.FirstOrDefault(i => !string.IsNullOrEmpty(i.MoviePrefix));
  195. }
  196. return null;
  197. }
  198. protected override string GetNameForMetadataLookup()
  199. {
  200. var name = base.GetNameForMetadataLookup();
  201. var listings = GetListingsProviderInfo();
  202. if (listings != null)
  203. {
  204. if (!string.IsNullOrEmpty(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringComparison.OrdinalIgnoreCase))
  205. {
  206. name = name.Substring(listings.MoviePrefix.Length).Trim();
  207. }
  208. }
  209. return name;
  210. }
  211. public override List<ExternalUrl> GetRelatedUrls()
  212. {
  213. var list = base.GetRelatedUrls();
  214. var imdbId = this.GetProviderId(MetadataProvider.Imdb);
  215. if (!string.IsNullOrEmpty(imdbId))
  216. {
  217. if (IsMovie)
  218. {
  219. list.Add(new ExternalUrl
  220. {
  221. Name = "Trakt",
  222. Url = string.Format(CultureInfo.InvariantCulture, "https://trakt.tv/movies/{0}", imdbId)
  223. });
  224. }
  225. }
  226. return list;
  227. }
  228. public string SeriesName { get; set; }
  229. }
  230. }