LiveTvChannel.cs 4.4 KB

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