2021-05-06 22:39:20 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-08-04 04:08:15 +00:00
|
|
|
#pragma warning disable CS1591, SA1306
|
2020-08-22 19:56:24 +00:00
|
|
|
|
2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Collections.Generic;
|
2019-02-28 22:22:57 +00:00
|
|
|
using System.Globalization;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Linq;
|
2019-10-15 15:49:49 +00:00
|
|
|
using System.Text.Json.Serialization;
|
2020-05-13 02:10:35 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2021-12-20 12:31:07 +00:00
|
|
|
using Jellyfin.Extensions;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Common.Configuration;
|
2019-01-13 19:25:32 +00:00
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 19:25:32 +00:00
|
|
|
using MediaBrowser.Model.LiveTv;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.LiveTv
|
|
|
|
{
|
|
|
|
public class LiveTvProgram : BaseItem, IHasLookupInfo<ItemLookupInfo>, IHasStartDate, IHasProgramAttributes
|
|
|
|
{
|
2023-10-07 22:40:58 +00:00
|
|
|
private const string EmbyServiceName = "Emby";
|
2021-08-04 04:08:15 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public LiveTvProgram()
|
|
|
|
{
|
|
|
|
IsVirtualItem = true;
|
|
|
|
}
|
|
|
|
|
2021-08-04 04:08:15 +00:00
|
|
|
public string SeriesName { get; set; }
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2019-01-13 20:31:14 +00:00
|
|
|
public override SourceType SourceType => SourceType.LiveTV;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-13 13:32:02 +00:00
|
|
|
/// Gets or sets start date of the program, in UTC.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public DateTime StartDate { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is repeat.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is repeat; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public bool IsRepeat { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the episode title.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The episode title.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public string EpisodeTitle { get; set; }
|
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public string ShowId { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is movie.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is movie; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public bool IsMovie { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2021-05-11 11:55:46 +00:00
|
|
|
/// Gets a value indicating whether this instance is sports.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2021-12-20 12:31:07 +00:00
|
|
|
public bool IsSports => Tags.Contains("Sports", StringComparison.OrdinalIgnoreCase);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this instance is series.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is series; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public bool IsSeries { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
2021-05-11 11:55:46 +00:00
|
|
|
/// Gets a value indicating whether this instance is live.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2021-12-20 12:31:07 +00:00
|
|
|
public bool IsLive => Tags.Contains("Live", StringComparison.OrdinalIgnoreCase);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-11 11:55:46 +00:00
|
|
|
/// Gets a value indicating whether this instance is news.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2021-12-20 12:31:07 +00:00
|
|
|
public bool IsNews => Tags.Contains("News", StringComparison.OrdinalIgnoreCase);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-11 11:55:46 +00:00
|
|
|
/// Gets a value indicating whether this instance is kids.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2021-12-20 12:31:07 +00:00
|
|
|
public bool IsKids => Tags.Contains("Kids", StringComparison.OrdinalIgnoreCase);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-11 11:55:46 +00:00
|
|
|
/// Gets a value indicating whether this instance is premiere.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2021-12-20 12:31:07 +00:00
|
|
|
public bool IsPremiere => Tags.Contains("Premiere", StringComparison.OrdinalIgnoreCase);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-11 11:55:46 +00:00
|
|
|
/// Gets the folder containing the item.
|
2020-06-15 22:37:52 +00:00
|
|
|
/// If the item is a folder, it returns the folder itself.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <value>The containing folder path.</value>
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2019-01-13 20:31:14 +00:00
|
|
|
public override string ContainingFolderPath => Path;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2021-06-06 15:16:41 +00:00
|
|
|
// [JsonIgnore]
|
2020-06-14 09:11:11 +00:00
|
|
|
// public override string MediaType
|
2021-06-06 15:16:41 +00:00
|
|
|
// {
|
2018-12-27 23:27:57 +00:00
|
|
|
// get
|
|
|
|
// {
|
|
|
|
// return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
|
|
|
|
// }
|
2021-06-06 15:16:41 +00:00
|
|
|
// }
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public bool IsAiring
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
|
|
return now >= StartDate && now < EndDate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public bool HasAired
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
|
|
return now >= EndDate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 04:08:15 +00:00
|
|
|
[JsonIgnore]
|
|
|
|
public override bool SupportsPeople
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// Optimization
|
|
|
|
if (IsNews || IsSports)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.SupportsPeople;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public override bool SupportsAncestors => false;
|
|
|
|
|
|
|
|
public override List<string> GetUserDataKeys()
|
|
|
|
{
|
|
|
|
var list = base.GetUserDataKeys();
|
|
|
|
|
|
|
|
if (!IsSeries)
|
|
|
|
{
|
|
|
|
var key = this.GetProviderId(MetadataProvider.Imdb);
|
|
|
|
if (!string.IsNullOrEmpty(key))
|
|
|
|
{
|
|
|
|
list.Insert(0, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
key = this.GetProviderId(MetadataProvider.Tmdb);
|
|
|
|
if (!string.IsNullOrEmpty(key))
|
|
|
|
{
|
|
|
|
list.Insert(0, key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!string.IsNullOrEmpty(EpisodeTitle))
|
|
|
|
{
|
|
|
|
var name = GetClientTypeName();
|
|
|
|
|
|
|
|
list.Insert(0, name + "-" + Name + (EpisodeTitle ?? string.Empty));
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override double GetDefaultPrimaryImageAspectRatio()
|
|
|
|
{
|
|
|
|
var serviceName = ServiceName;
|
|
|
|
|
|
|
|
if (string.Equals(serviceName, EmbyServiceName, StringComparison.OrdinalIgnoreCase) || string.Equals(serviceName, "Next Pvr", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return 2.0 / 3;
|
|
|
|
}
|
2023-04-06 17:38:34 +00:00
|
|
|
|
|
|
|
return 16.0 / 9;
|
2021-08-04 04:08:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public override string GetClientTypeName()
|
|
|
|
{
|
|
|
|
return "Program";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override UnratedItem GetBlockUnratedType()
|
|
|
|
{
|
|
|
|
return UnratedItem.LiveTvProgram;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override string GetInternalMetadataPath(string basePath)
|
|
|
|
{
|
2019-02-28 22:22:57 +00:00
|
|
|
return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N", CultureInfo.InvariantCulture));
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool CanDelete()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private LiveTvOptions GetConfiguration()
|
|
|
|
{
|
|
|
|
return ConfigurationManager.GetConfiguration<LiveTvOptions>("livetv");
|
|
|
|
}
|
|
|
|
|
|
|
|
private ListingsProviderInfo GetListingsProviderInfo()
|
|
|
|
{
|
|
|
|
if (string.Equals(ServiceName, "Emby", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
var config = GetConfiguration();
|
|
|
|
|
|
|
|
return config.ListingProviders.FirstOrDefault(i => !string.IsNullOrEmpty(i.MoviePrefix));
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override string GetNameForMetadataLookup()
|
|
|
|
{
|
|
|
|
var name = base.GetNameForMetadataLookup();
|
|
|
|
|
|
|
|
var listings = GetListingsProviderInfo();
|
|
|
|
|
2022-12-05 14:01:13 +00:00
|
|
|
if (listings is not null)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
name = name.Substring(listings.MoviePrefix.Length).Trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override List<ExternalUrl> GetRelatedUrls()
|
|
|
|
{
|
|
|
|
var list = base.GetRelatedUrls();
|
|
|
|
|
2020-06-06 19:17:49 +00:00
|
|
|
var imdbId = this.GetProviderId(MetadataProvider.Imdb);
|
2018-12-27 23:27:57 +00:00
|
|
|
if (!string.IsNullOrEmpty(imdbId))
|
|
|
|
{
|
|
|
|
if (IsMovie)
|
|
|
|
{
|
|
|
|
list.Add(new ExternalUrl
|
|
|
|
{
|
|
|
|
Name = "Trakt",
|
2020-08-07 17:26:28 +00:00
|
|
|
Url = string.Format(CultureInfo.InvariantCulture, "https://trakt.tv/movies/{0}", imdbId)
|
2018-12-27 23:27:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|