| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591, SA1306 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Globalization; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Text.Json.Serialization; |
| | 10 | | using Jellyfin.Data.Enums; |
| | 11 | | using Jellyfin.Extensions; |
| | 12 | | using MediaBrowser.Common.Configuration; |
| | 13 | | using MediaBrowser.Controller.Entities; |
| | 14 | | using MediaBrowser.Controller.Providers; |
| | 15 | | using MediaBrowser.Model.Entities; |
| | 16 | | using MediaBrowser.Model.LiveTv; |
| | 17 | | using MediaBrowser.Model.Providers; |
| | 18 | |
|
| | 19 | | namespace MediaBrowser.Controller.LiveTv |
| | 20 | | { |
| | 21 | | public class LiveTvProgram : BaseItem, IHasLookupInfo<ItemLookupInfo>, IHasStartDate, IHasProgramAttributes |
| | 22 | | { |
| | 23 | | private const string EmbyServiceName = "Emby"; |
| | 24 | |
|
| 1 | 25 | | public LiveTvProgram() |
| | 26 | | { |
| 1 | 27 | | IsVirtualItem = true; |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | | public string SeriesName { get; set; } |
| | 31 | |
|
| | 32 | | [JsonIgnore] |
| 0 | 33 | | public override SourceType SourceType => SourceType.LiveTV; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Gets or sets start date of the program, in UTC. |
| | 37 | | /// </summary> |
| | 38 | | [JsonIgnore] |
| | 39 | | public DateTime StartDate { get; set; } |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets or sets a value indicating whether this instance is repeat. |
| | 43 | | /// </summary> |
| | 44 | | /// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value> |
| | 45 | | [JsonIgnore] |
| | 46 | | public bool IsRepeat { get; set; } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets or sets the episode title. |
| | 50 | | /// </summary> |
| | 51 | | /// <value>The episode title.</value> |
| | 52 | | [JsonIgnore] |
| | 53 | | public string EpisodeTitle { get; set; } |
| | 54 | |
|
| | 55 | | [JsonIgnore] |
| | 56 | | public string ShowId { get; set; } |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Gets or sets a value indicating whether this instance is movie. |
| | 60 | | /// </summary> |
| | 61 | | /// <value><c>true</c> if this instance is movie; otherwise, <c>false</c>.</value> |
| | 62 | | [JsonIgnore] |
| | 63 | | public bool IsMovie { get; set; } |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Gets a value indicating whether this instance is sports. |
| | 67 | | /// </summary> |
| | 68 | | /// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value> |
| | 69 | | [JsonIgnore] |
| 0 | 70 | | public bool IsSports => Tags.Contains("Sports", StringComparison.OrdinalIgnoreCase); |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Gets or sets a value indicating whether this instance is series. |
| | 74 | | /// </summary> |
| | 75 | | /// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value> |
| | 76 | | [JsonIgnore] |
| | 77 | | public bool IsSeries { get; set; } |
| | 78 | |
|
| | 79 | | /// <summary> |
| | 80 | | /// Gets a value indicating whether this instance is live. |
| | 81 | | /// </summary> |
| | 82 | | /// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value> |
| | 83 | | [JsonIgnore] |
| 0 | 84 | | public bool IsLive => Tags.Contains("Live", StringComparison.OrdinalIgnoreCase); |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Gets a value indicating whether this instance is news. |
| | 88 | | /// </summary> |
| | 89 | | /// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value> |
| | 90 | | [JsonIgnore] |
| 0 | 91 | | public bool IsNews => Tags.Contains("News", StringComparison.OrdinalIgnoreCase); |
| | 92 | |
|
| | 93 | | /// <summary> |
| | 94 | | /// Gets a value indicating whether this instance is kids. |
| | 95 | | /// </summary> |
| | 96 | | /// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value> |
| | 97 | | [JsonIgnore] |
| 0 | 98 | | public bool IsKids => Tags.Contains("Kids", StringComparison.OrdinalIgnoreCase); |
| | 99 | |
|
| | 100 | | /// <summary> |
| | 101 | | /// Gets a value indicating whether this instance is premiere. |
| | 102 | | /// </summary> |
| | 103 | | /// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value> |
| | 104 | | [JsonIgnore] |
| 0 | 105 | | public bool IsPremiere => Tags.Contains("Premiere", StringComparison.OrdinalIgnoreCase); |
| | 106 | |
|
| | 107 | | /// <summary> |
| | 108 | | /// Gets the folder containing the item. |
| | 109 | | /// If the item is a folder, it returns the folder itself. |
| | 110 | | /// </summary> |
| | 111 | | /// <value>The containing folder path.</value> |
| | 112 | | [JsonIgnore] |
| 0 | 113 | | public override string ContainingFolderPath => Path; |
| | 114 | |
|
| | 115 | | // [JsonIgnore] |
| | 116 | | // public override string MediaType |
| | 117 | | // { |
| | 118 | | // get |
| | 119 | | // { |
| | 120 | | // return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio |
| | 121 | | // } |
| | 122 | | // } |
| | 123 | |
|
| | 124 | | [JsonIgnore] |
| | 125 | | public bool IsAiring |
| | 126 | | { |
| | 127 | | get |
| | 128 | | { |
| 0 | 129 | | var now = DateTime.UtcNow; |
| | 130 | |
|
| 0 | 131 | | return now >= StartDate && now < EndDate; |
| | 132 | | } |
| | 133 | | } |
| | 134 | |
|
| | 135 | | [JsonIgnore] |
| | 136 | | public bool HasAired |
| | 137 | | { |
| | 138 | | get |
| | 139 | | { |
| 0 | 140 | | var now = DateTime.UtcNow; |
| | 141 | |
|
| 0 | 142 | | return now >= EndDate; |
| | 143 | | } |
| | 144 | | } |
| | 145 | |
|
| | 146 | | [JsonIgnore] |
| | 147 | | public override bool SupportsPeople |
| | 148 | | { |
| | 149 | | get |
| | 150 | | { |
| | 151 | | // Optimization |
| 0 | 152 | | if (IsNews || IsSports) |
| | 153 | | { |
| 0 | 154 | | return false; |
| | 155 | | } |
| | 156 | |
|
| 0 | 157 | | return base.SupportsPeople; |
| | 158 | | } |
| | 159 | | } |
| | 160 | |
|
| | 161 | | [JsonIgnore] |
| 0 | 162 | | public override bool SupportsAncestors => false; |
| | 163 | |
|
| | 164 | | public override List<string> GetUserDataKeys() |
| | 165 | | { |
| 0 | 166 | | var list = base.GetUserDataKeys(); |
| | 167 | |
|
| 0 | 168 | | if (!IsSeries) |
| | 169 | | { |
| 0 | 170 | | var key = this.GetProviderId(MetadataProvider.Imdb); |
| 0 | 171 | | if (!string.IsNullOrEmpty(key)) |
| | 172 | | { |
| 0 | 173 | | list.Insert(0, key); |
| | 174 | | } |
| | 175 | |
|
| 0 | 176 | | key = this.GetProviderId(MetadataProvider.Tmdb); |
| 0 | 177 | | if (!string.IsNullOrEmpty(key)) |
| | 178 | | { |
| 0 | 179 | | list.Insert(0, key); |
| | 180 | | } |
| | 181 | | } |
| 0 | 182 | | else if (!string.IsNullOrEmpty(EpisodeTitle)) |
| | 183 | | { |
| 0 | 184 | | var name = GetClientTypeName(); |
| | 185 | |
|
| 0 | 186 | | list.Insert(0, name + "-" + Name + (EpisodeTitle ?? string.Empty)); |
| | 187 | | } |
| | 188 | |
|
| 0 | 189 | | return list; |
| | 190 | | } |
| | 191 | |
|
| | 192 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | 193 | | { |
| 0 | 194 | | var serviceName = ServiceName; |
| | 195 | |
|
| 0 | 196 | | if (string.Equals(serviceName, EmbyServiceName, StringComparison.OrdinalIgnoreCase) || string.Equals(service |
| | 197 | | { |
| 0 | 198 | | return 2.0 / 3; |
| | 199 | | } |
| | 200 | |
|
| 0 | 201 | | return 16.0 / 9; |
| | 202 | | } |
| | 203 | |
|
| | 204 | | public override string GetClientTypeName() |
| | 205 | | { |
| 1 | 206 | | return "Program"; |
| | 207 | | } |
| | 208 | |
|
| | 209 | | public override UnratedItem GetBlockUnratedType() |
| | 210 | | { |
| 0 | 211 | | return UnratedItem.LiveTvProgram; |
| | 212 | | } |
| | 213 | |
|
| | 214 | | protected override string GetInternalMetadataPath(string basePath) |
| | 215 | | { |
| 0 | 216 | | return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N", CultureInfo.InvariantCulture)); |
| | 217 | | } |
| | 218 | |
|
| | 219 | | public override bool CanDelete() |
| | 220 | | { |
| 0 | 221 | | return false; |
| | 222 | | } |
| | 223 | |
|
| | 224 | | private LiveTvOptions GetConfiguration() |
| | 225 | | { |
| 0 | 226 | | return ConfigurationManager.GetConfiguration<LiveTvOptions>("livetv"); |
| | 227 | | } |
| | 228 | |
|
| | 229 | | private ListingsProviderInfo GetListingsProviderInfo() |
| | 230 | | { |
| 0 | 231 | | if (string.Equals(ServiceName, "Emby", StringComparison.OrdinalIgnoreCase)) |
| | 232 | | { |
| 0 | 233 | | var config = GetConfiguration(); |
| | 234 | |
|
| 0 | 235 | | return config.ListingProviders.FirstOrDefault(i => !string.IsNullOrEmpty(i.MoviePrefix)); |
| | 236 | | } |
| | 237 | |
|
| 0 | 238 | | return null; |
| | 239 | | } |
| | 240 | |
|
| | 241 | | protected override string GetNameForMetadataLookup() |
| | 242 | | { |
| 0 | 243 | | var name = base.GetNameForMetadataLookup(); |
| | 244 | |
|
| 0 | 245 | | var listings = GetListingsProviderInfo(); |
| | 246 | |
|
| 0 | 247 | | if (listings is not null) |
| | 248 | | { |
| 0 | 249 | | if (!string.IsNullOrEmpty(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringCompariso |
| | 250 | | { |
| 0 | 251 | | name = name.Substring(listings.MoviePrefix.Length).Trim(); |
| | 252 | | } |
| | 253 | | } |
| | 254 | |
|
| 0 | 255 | | return name; |
| | 256 | | } |
| | 257 | | } |
| | 258 | | } |