LiveTvChannel.cs 4.1 KB

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