LiveTvChannel.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 MediaBrowser.Model.Users;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Runtime.Serialization;
  11. namespace MediaBrowser.Controller.LiveTv
  12. {
  13. public class LiveTvChannel : BaseItem, IHasMediaSources, ILiveTvItem
  14. {
  15. /// <summary>
  16. /// Gets the user data key.
  17. /// </summary>
  18. /// <returns>System.String.</returns>
  19. protected override string CreateUserDataKey()
  20. {
  21. return GetClientTypeName() + "-" + Name;
  22. }
  23. protected override bool GetBlockUnratedValue(UserPolicy config)
  24. {
  25. return config.BlockUnratedItems.Contains(UnratedItem.LiveTvChannel);
  26. }
  27. /// <summary>
  28. /// Gets a value indicating whether this instance is owned item.
  29. /// </summary>
  30. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  31. [IgnoreDataMember]
  32. public override bool IsOwnedItem
  33. {
  34. get
  35. {
  36. return false;
  37. }
  38. }
  39. /// <summary>
  40. /// Gets or sets the number.
  41. /// </summary>
  42. /// <value>The number.</value>
  43. public string Number { get; set; }
  44. /// <summary>
  45. /// Gets or sets the external identifier.
  46. /// </summary>
  47. /// <value>The external identifier.</value>
  48. public string ExternalId { get; set; }
  49. /// <summary>
  50. /// Gets or sets the type of the channel.
  51. /// </summary>
  52. /// <value>The type of the channel.</value>
  53. public ChannelType ChannelType { get; set; }
  54. /// <summary>
  55. /// Gets or sets the name of the service.
  56. /// </summary>
  57. /// <value>The name of the service.</value>
  58. public string ServiceName { get; set; }
  59. /// <summary>
  60. /// Supply the image path if it can be accessed directly from the file system
  61. /// </summary>
  62. /// <value>The image path.</value>
  63. public string ProviderImagePath { get; set; }
  64. /// <summary>
  65. /// Supply the image url if it can be downloaded
  66. /// </summary>
  67. /// <value>The image URL.</value>
  68. public string ProviderImageUrl { get; set; }
  69. /// <summary>
  70. /// Gets or sets a value indicating whether this instance has image.
  71. /// </summary>
  72. /// <value><c>null</c> if [has image] contains no value, <c>true</c> if [has image]; otherwise, <c>false</c>.</value>
  73. public bool? HasProviderImage { get; set; }
  74. public override LocationType LocationType
  75. {
  76. get
  77. {
  78. // TODO: This should be removed
  79. return LocationType.Remote;
  80. }
  81. }
  82. protected override string CreateSortName()
  83. {
  84. double number = 0;
  85. if (!string.IsNullOrEmpty(Number))
  86. {
  87. double.TryParse(Number, out number);
  88. }
  89. return number.ToString("000-") + (Name ?? string.Empty);
  90. }
  91. [IgnoreDataMember]
  92. public override string MediaType
  93. {
  94. get
  95. {
  96. return ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
  97. }
  98. }
  99. public override string GetClientTypeName()
  100. {
  101. return "TvChannel";
  102. }
  103. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  104. {
  105. return new List<BaseItem>();
  106. }
  107. public IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  108. {
  109. var list = new List<MediaSourceInfo>();
  110. var locationType = LocationType;
  111. var info = new MediaSourceInfo
  112. {
  113. Id = Id.ToString("N"),
  114. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  115. MediaStreams = new List<MediaStream>(),
  116. Name = Name,
  117. Path = Path,
  118. RunTimeTicks = RunTimeTicks,
  119. Type = MediaSourceType.Placeholder
  120. };
  121. list.Add(info);
  122. return list;
  123. }
  124. protected override string GetInternalMetadataPath(string basePath)
  125. {
  126. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"), "metadata");
  127. }
  128. public override bool CanDelete()
  129. {
  130. return false;
  131. }
  132. }
  133. }