LiveTvChannel.cs 5.0 KB

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