LiveTvChannel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System.Runtime.Serialization;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Model.Configuration;
  4. using MediaBrowser.Model.Dto;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.LiveTv;
  7. using MediaBrowser.Model.MediaInfo;
  8. using MediaBrowser.Model.Users;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. namespace MediaBrowser.Controller.LiveTv
  12. {
  13. public class LiveTvChannel : BaseItem, IHasMediaSources
  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. public string ServiceName { get; set; }
  55. /// <summary>
  56. /// Supply the image path if it can be accessed directly from the file system
  57. /// </summary>
  58. /// <value>The image path.</value>
  59. public string ProviderImagePath { get; set; }
  60. /// <summary>
  61. /// Supply the image url if it can be downloaded
  62. /// </summary>
  63. /// <value>The image URL.</value>
  64. public string ProviderImageUrl { get; set; }
  65. /// <summary>
  66. /// Gets or sets a value indicating whether this instance has image.
  67. /// </summary>
  68. /// <value><c>null</c> if [has image] contains no value, <c>true</c> if [has image]; otherwise, <c>false</c>.</value>
  69. public bool? HasProviderImage { get; set; }
  70. protected override string CreateSortName()
  71. {
  72. double number = 0;
  73. if (!string.IsNullOrEmpty(Number))
  74. {
  75. double.TryParse(Number, out number);
  76. }
  77. return number.ToString("000-") + (Name ?? string.Empty);
  78. }
  79. [IgnoreDataMember]
  80. public override string MediaType
  81. {
  82. get
  83. {
  84. return ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
  85. }
  86. }
  87. public override string GetClientTypeName()
  88. {
  89. return "TvChannel";
  90. }
  91. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  92. {
  93. return new List<BaseItem>();
  94. }
  95. public IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  96. {
  97. var list = new List<MediaSourceInfo>();
  98. var locationType = LocationType;
  99. var info = new MediaSourceInfo
  100. {
  101. Id = Id.ToString("N"),
  102. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  103. MediaStreams = new List<MediaStream>(),
  104. Name = Name,
  105. Path = Path,
  106. RunTimeTicks = RunTimeTicks,
  107. Type = MediaSourceType.Default
  108. };
  109. list.Add(info);
  110. return list;
  111. }
  112. protected override string GetInternalMetadataPath(string basePath)
  113. {
  114. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"), "metadata");
  115. }
  116. }
  117. }