LiveTvChannel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text.Json.Serialization;
  8. using Jellyfin.Data.Enums;
  9. using MediaBrowser.Controller.Entities;
  10. using MediaBrowser.Model.Dto;
  11. using MediaBrowser.Model.Entities;
  12. using MediaBrowser.Model.LiveTv;
  13. using MediaBrowser.Model.MediaInfo;
  14. namespace MediaBrowser.Controller.LiveTv
  15. {
  16. public class LiveTvChannel : BaseItem, IHasMediaSources, IHasProgramAttributes
  17. {
  18. [JsonIgnore]
  19. public override bool SupportsPositionTicksResume => false;
  20. [JsonIgnore]
  21. public override SourceType SourceType => SourceType.LiveTV;
  22. [JsonIgnore]
  23. public override bool EnableRememberingTrackSelections => false;
  24. /// <summary>
  25. /// Gets or sets the number.
  26. /// </summary>
  27. /// <value>The number.</value>
  28. public string Number { get; set; }
  29. /// <summary>
  30. /// Gets or sets the type of the channel.
  31. /// </summary>
  32. /// <value>The type of the channel.</value>
  33. public ChannelType ChannelType { get; set; }
  34. [JsonIgnore]
  35. public override LocationType LocationType => LocationType.Remote;
  36. [JsonIgnore]
  37. public override string MediaType => ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video;
  38. [JsonIgnore]
  39. public bool IsMovie { get; set; }
  40. /// <summary>
  41. /// Gets or sets a value indicating whether this instance is sports.
  42. /// </summary>
  43. /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
  44. [JsonIgnore]
  45. public bool IsSports { get; set; }
  46. /// <summary>
  47. /// Gets or sets a value indicating whether this instance is series.
  48. /// </summary>
  49. /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
  50. [JsonIgnore]
  51. public bool IsSeries { get; set; }
  52. /// <summary>
  53. /// Gets or sets a value indicating whether this instance is news.
  54. /// </summary>
  55. /// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
  56. [JsonIgnore]
  57. public bool IsNews { get; set; }
  58. /// <summary>
  59. /// Gets a value indicating whether this instance is kids.
  60. /// </summary>
  61. /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
  62. [JsonIgnore]
  63. public bool IsKids => Tags.Contains("Kids", StringComparer.OrdinalIgnoreCase);
  64. [JsonIgnore]
  65. public bool IsRepeat { get; set; }
  66. /// <summary>
  67. /// Gets or sets the episode title.
  68. /// </summary>
  69. /// <value>The episode title.</value>
  70. [JsonIgnore]
  71. public string EpisodeTitle { get; set; }
  72. public override List<string> GetUserDataKeys()
  73. {
  74. var list = base.GetUserDataKeys();
  75. if (!ConfigurationManager.Configuration.DisableLiveTvChannelUserDataName)
  76. {
  77. list.Insert(0, GetClientTypeName() + "-" + Name);
  78. }
  79. return list;
  80. }
  81. public override UnratedItem GetBlockUnratedType()
  82. {
  83. return UnratedItem.LiveTvChannel;
  84. }
  85. protected override string CreateSortName()
  86. {
  87. if (!string.IsNullOrEmpty(Number))
  88. {
  89. double number = 0;
  90. if (double.TryParse(Number, NumberStyles.Any, CultureInfo.InvariantCulture, out number))
  91. {
  92. return string.Format(CultureInfo.InvariantCulture, "{0:00000.0}", number) + "-" + (Name ?? string.Empty);
  93. }
  94. }
  95. return (Number ?? string.Empty) + "-" + (Name ?? string.Empty);
  96. }
  97. public override string GetClientTypeName()
  98. {
  99. return "TvChannel";
  100. }
  101. public IEnumerable<BaseItem> GetTaggedItems()
  102. {
  103. return new List<BaseItem>();
  104. }
  105. public override List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  106. {
  107. var list = new List<MediaSourceInfo>();
  108. var info = new MediaSourceInfo
  109. {
  110. Id = Id.ToString("N", CultureInfo.InvariantCulture),
  111. Protocol = PathProtocol ?? MediaProtocol.File,
  112. MediaStreams = new List<MediaStream>(),
  113. Name = Name,
  114. Path = Path,
  115. RunTimeTicks = RunTimeTicks,
  116. Type = MediaSourceType.Placeholder,
  117. IsInfiniteStream = RunTimeTicks == null
  118. };
  119. list.Add(info);
  120. return list;
  121. }
  122. public override List<MediaStream> GetMediaStreams()
  123. {
  124. return new List<MediaStream>();
  125. }
  126. protected override string GetInternalMetadataPath(string basePath)
  127. {
  128. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N", CultureInfo.InvariantCulture), "metadata");
  129. }
  130. public override bool CanDelete()
  131. {
  132. return false;
  133. }
  134. }
  135. }