LiveTvChannel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Configuration;
  3. using MediaBrowser.Model.Dto;
  4. using MediaBrowser.Model.Entities;
  5. using MediaBrowser.Model.LiveTv;
  6. using MediaBrowser.Model.MediaInfo;
  7. using System.Collections.Generic;
  8. using System.Globalization;
  9. using MediaBrowser.Model.Serialization;
  10. namespace MediaBrowser.Controller.LiveTv
  11. {
  12. public class LiveTvChannel : BaseItem, IHasMediaSources, IHasProgramAttributes
  13. {
  14. public override List<string> GetUserDataKeys()
  15. {
  16. var list = base.GetUserDataKeys();
  17. if (!ConfigurationManager.Configuration.DisableLiveTvChannelUserDataName)
  18. {
  19. list.Insert(0, GetClientTypeName() + "-" + Name);
  20. }
  21. return list;
  22. }
  23. public bool SupportsMediaSourceSelection()
  24. {
  25. return false;
  26. }
  27. public override UnratedItem GetBlockUnratedType()
  28. {
  29. return UnratedItem.LiveTvChannel;
  30. }
  31. /// <summary>
  32. /// Gets a value indicating whether this instance is owned item.
  33. /// </summary>
  34. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  35. [IgnoreDataMember]
  36. public override bool IsOwnedItem
  37. {
  38. get
  39. {
  40. return false;
  41. }
  42. }
  43. [IgnoreDataMember]
  44. public override bool SupportsPositionTicksResume
  45. {
  46. get
  47. {
  48. return false;
  49. }
  50. }
  51. [IgnoreDataMember]
  52. public override SourceType SourceType
  53. {
  54. get { return SourceType.LiveTV; }
  55. }
  56. [IgnoreDataMember]
  57. public override bool EnableRememberingTrackSelections
  58. {
  59. get
  60. {
  61. return false;
  62. }
  63. }
  64. /// <summary>
  65. /// Gets or sets the number.
  66. /// </summary>
  67. /// <value>The number.</value>
  68. public string Number { get; set; }
  69. /// <summary>
  70. /// Gets or sets the type of the channel.
  71. /// </summary>
  72. /// <value>The type of the channel.</value>
  73. public ChannelType ChannelType { get; set; }
  74. [IgnoreDataMember]
  75. public override LocationType LocationType
  76. {
  77. get
  78. {
  79. // TODO: This should be removed
  80. return LocationType.Remote;
  81. }
  82. }
  83. protected override string CreateSortName()
  84. {
  85. if (!string.IsNullOrEmpty(Number))
  86. {
  87. double number = 0;
  88. if (double.TryParse(Number, NumberStyles.Any, CultureInfo.InvariantCulture, out number))
  89. {
  90. return string.Format("{0:00000.0}", number) + "-" + (Name ?? string.Empty);
  91. }
  92. }
  93. return (Number ?? string.Empty) + "-" + (Name ?? string.Empty);
  94. }
  95. [IgnoreDataMember]
  96. public override string MediaType
  97. {
  98. get
  99. {
  100. return ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
  101. }
  102. }
  103. public override string GetClientTypeName()
  104. {
  105. return "TvChannel";
  106. }
  107. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  108. {
  109. return new List<BaseItem>();
  110. }
  111. public List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  112. {
  113. var list = new List<MediaSourceInfo>();
  114. var locationType = LocationType;
  115. var info = new MediaSourceInfo
  116. {
  117. Id = Id.ToString("N"),
  118. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  119. MediaStreams = new List<MediaStream>(),
  120. Name = Name,
  121. Path = Path,
  122. RunTimeTicks = RunTimeTicks,
  123. Type = MediaSourceType.Placeholder,
  124. IsInfiniteStream = RunTimeTicks == null
  125. };
  126. list.Add(info);
  127. return list;
  128. }
  129. public List<MediaStream> GetMediaStreams()
  130. {
  131. return new List<MediaStream>();
  132. }
  133. protected override string GetInternalMetadataPath(string basePath)
  134. {
  135. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"), "metadata");
  136. }
  137. public override bool CanDelete()
  138. {
  139. return false;
  140. }
  141. [IgnoreDataMember]
  142. public bool IsMovie { get; set; }
  143. /// <summary>
  144. /// Gets or sets a value indicating whether this instance is sports.
  145. /// </summary>
  146. /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
  147. [IgnoreDataMember]
  148. public bool IsSports { get; set; }
  149. /// <summary>
  150. /// Gets or sets a value indicating whether this instance is series.
  151. /// </summary>
  152. /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
  153. [IgnoreDataMember]
  154. public bool IsSeries { get; set; }
  155. /// <summary>
  156. /// Gets or sets a value indicating whether this instance is live.
  157. /// </summary>
  158. /// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
  159. [IgnoreDataMember]
  160. public bool IsLive { get; set; }
  161. /// <summary>
  162. /// Gets or sets a value indicating whether this instance is news.
  163. /// </summary>
  164. /// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
  165. [IgnoreDataMember]
  166. public bool IsNews { get; set; }
  167. /// <summary>
  168. /// Gets or sets a value indicating whether this instance is kids.
  169. /// </summary>
  170. /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
  171. [IgnoreDataMember]
  172. public bool IsKids { get; set; }
  173. [IgnoreDataMember]
  174. public bool IsPremiere { get; set; }
  175. [IgnoreDataMember]
  176. public bool IsRepeat { get; set; }
  177. /// <summary>
  178. /// Gets or sets the episode title.
  179. /// </summary>
  180. /// <value>The episode title.</value>
  181. [IgnoreDataMember]
  182. public string EpisodeTitle { get; set; }
  183. }
  184. }