LiveTvChannel.cs 4.9 KB

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