LiveTvChannel.cs 4.4 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 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. protected override string CreateSortName()
  75. {
  76. double number = 0;
  77. if (!string.IsNullOrEmpty(Number))
  78. {
  79. double.TryParse(Number, out number);
  80. }
  81. return number.ToString("000-") + (Name ?? string.Empty);
  82. }
  83. [IgnoreDataMember]
  84. public override string MediaType
  85. {
  86. get
  87. {
  88. return ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
  89. }
  90. }
  91. public override string GetClientTypeName()
  92. {
  93. return "TvChannel";
  94. }
  95. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  96. {
  97. return new List<BaseItem>();
  98. }
  99. public IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  100. {
  101. var list = new List<MediaSourceInfo>();
  102. var locationType = LocationType;
  103. var info = new MediaSourceInfo
  104. {
  105. Id = Id.ToString("N"),
  106. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  107. MediaStreams = new List<MediaStream>(),
  108. Name = Name,
  109. Path = Path,
  110. RunTimeTicks = RunTimeTicks,
  111. Type = MediaSourceType.Placeholder
  112. };
  113. list.Add(info);
  114. return list;
  115. }
  116. protected override string GetInternalMetadataPath(string basePath)
  117. {
  118. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"), "metadata");
  119. }
  120. public override bool CanDelete()
  121. {
  122. return false;
  123. }
  124. }
  125. }