LiveTvChannel.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. namespace MediaBrowser.Controller.LiveTv
  10. {
  11. public class LiveTvChannel : BaseItem, IHasMediaSources
  12. {
  13. /// <summary>
  14. /// Gets the user data key.
  15. /// </summary>
  16. /// <returns>System.String.</returns>
  17. public override string GetUserDataKey()
  18. {
  19. return GetClientTypeName() + "-" + Name;
  20. }
  21. /// <summary>
  22. /// Returns the folder containing the item.
  23. /// If the item is a folder, it returns the folder itself
  24. /// </summary>
  25. /// <value>The containing folder path.</value>
  26. public override string ContainingFolderPath
  27. {
  28. get
  29. {
  30. return Path;
  31. }
  32. }
  33. protected override bool GetBlockUnratedValue(UserConfiguration config)
  34. {
  35. return config.BlockUnratedItems.Contains(UnratedItem.LiveTvChannel);
  36. }
  37. /// <summary>
  38. /// Gets a value indicating whether this instance is owned item.
  39. /// </summary>
  40. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  41. public override bool IsOwnedItem
  42. {
  43. get
  44. {
  45. return false;
  46. }
  47. }
  48. public override bool IsSaveLocalMetadataEnabled()
  49. {
  50. return true;
  51. }
  52. /// <summary>
  53. /// Gets or sets the number.
  54. /// </summary>
  55. /// <value>The number.</value>
  56. public string Number { get; set; }
  57. /// <summary>
  58. /// Gets or sets the external identifier.
  59. /// </summary>
  60. /// <value>The external identifier.</value>
  61. public string ExternalId { get; set; }
  62. /// <summary>
  63. /// Gets or sets the type of the channel.
  64. /// </summary>
  65. /// <value>The type of the channel.</value>
  66. public ChannelType ChannelType { get; set; }
  67. public string ServiceName { get; set; }
  68. /// <summary>
  69. /// Supply the image path if it can be accessed directly from the file system
  70. /// </summary>
  71. /// <value>The image path.</value>
  72. public string ProviderImagePath { get; set; }
  73. /// <summary>
  74. /// Supply the image url if it can be downloaded
  75. /// </summary>
  76. /// <value>The image URL.</value>
  77. public string ProviderImageUrl { get; set; }
  78. /// <summary>
  79. /// Gets or sets a value indicating whether this instance has image.
  80. /// </summary>
  81. /// <value><c>null</c> if [has image] contains no value, <c>true</c> if [has image]; otherwise, <c>false</c>.</value>
  82. public bool? HasProviderImage { get; set; }
  83. protected override string CreateSortName()
  84. {
  85. double number = 0;
  86. if (!string.IsNullOrEmpty(Number))
  87. {
  88. double.TryParse(Number, out number);
  89. }
  90. return number.ToString("000-") + (Name ?? string.Empty);
  91. }
  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.Default
  120. };
  121. list.Add(info);
  122. return list;
  123. }
  124. }
  125. }