LiveTvChannel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. public override UnratedItem GetBlockUnratedType()
  24. {
  25. return 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 type of the channel.
  46. /// </summary>
  47. /// <value>The type of the channel.</value>
  48. public ChannelType ChannelType { get; set; }
  49. /// <summary>
  50. /// Gets or sets the name of the service.
  51. /// </summary>
  52. /// <value>The name of the service.</value>
  53. public string ServiceName { get; set; }
  54. [IgnoreDataMember]
  55. public override LocationType LocationType
  56. {
  57. get
  58. {
  59. // TODO: This should be removed
  60. return LocationType.Remote;
  61. }
  62. }
  63. protected override string CreateSortName()
  64. {
  65. double number = 0;
  66. if (!string.IsNullOrEmpty(Number))
  67. {
  68. double.TryParse(Number, out number);
  69. }
  70. return number.ToString("000-") + (Name ?? string.Empty);
  71. }
  72. [IgnoreDataMember]
  73. public override string MediaType
  74. {
  75. get
  76. {
  77. return ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
  78. }
  79. }
  80. public override string GetClientTypeName()
  81. {
  82. return "TvChannel";
  83. }
  84. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  85. {
  86. return new List<BaseItem>();
  87. }
  88. public IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  89. {
  90. var list = new List<MediaSourceInfo>();
  91. var locationType = LocationType;
  92. var info = new MediaSourceInfo
  93. {
  94. Id = Id.ToString("N"),
  95. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  96. MediaStreams = new List<MediaStream>(),
  97. Name = Name,
  98. Path = Path,
  99. RunTimeTicks = RunTimeTicks,
  100. Type = MediaSourceType.Placeholder
  101. };
  102. list.Add(info);
  103. return list;
  104. }
  105. protected override string GetInternalMetadataPath(string basePath)
  106. {
  107. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"), "metadata");
  108. }
  109. public override bool CanDelete()
  110. {
  111. return false;
  112. }
  113. }
  114. }