LiveTvChannel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Text.Json.Serialization;
  7. using Jellyfin.Data.Enums;
  8. using Jellyfin.Extensions;
  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", StringComparison.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. if (double.TryParse(Number, NumberStyles.Any, CultureInfo.InvariantCulture, out double number))
  90. {
  91. return string.Format(CultureInfo.InvariantCulture, "{0:00000.0}", number) + "-" + (Name ?? string.Empty);
  92. }
  93. }
  94. return (Number ?? string.Empty) + "-" + (Name ?? string.Empty);
  95. }
  96. public override string GetClientTypeName()
  97. {
  98. return "TvChannel";
  99. }
  100. public IEnumerable<BaseItem> GetTaggedItems()
  101. {
  102. return new List<BaseItem>();
  103. }
  104. public override List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  105. {
  106. var list = new List<MediaSourceInfo>();
  107. var info = new MediaSourceInfo
  108. {
  109. Id = Id.ToString("N", CultureInfo.InvariantCulture),
  110. Protocol = PathProtocol ?? MediaProtocol.File,
  111. MediaStreams = Array.Empty<MediaStream>(),
  112. Name = Name,
  113. Path = Path,
  114. RunTimeTicks = RunTimeTicks,
  115. Type = MediaSourceType.Placeholder,
  116. IsInfiniteStream = RunTimeTicks == null
  117. };
  118. list.Add(info);
  119. return list;
  120. }
  121. public override List<MediaStream> GetMediaStreams()
  122. {
  123. return new List<MediaStream>();
  124. }
  125. protected override string GetInternalMetadataPath(string basePath)
  126. {
  127. return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N", CultureInfo.InvariantCulture), "metadata");
  128. }
  129. public override bool CanDelete()
  130. {
  131. return false;
  132. }
  133. }
  134. }