2021-05-06 22:39:20 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-08-22 19:56:24 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
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;
|
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
|
|
|
|
{
|
|
|
|
public LiveTvProgram()
|
|
|
|
{
|
|
|
|
IsVirtualItem = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override List<string> GetUserDataKeys()
|
|
|
|
{
|
|
|
|
var list = base.GetUserDataKeys();
|
|
|
|
|
|
|
|
if (!IsSeries)
|
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
var key = this.GetProviderId(MetadataProvider.Imdb);
|
2018-12-27 23:27:57 +00:00
|
|
|
if (!string.IsNullOrEmpty(key))
|
|
|
|
{
|
|
|
|
list.Insert(0, key);
|
|
|
|
}
|
|
|
|
|
2020-06-06 19:17:49 +00:00
|
|
|
key = this.GetProviderId(MetadataProvider.Tmdb);
|
2018-12-27 23:27:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-27 21:43:48 +00:00
|
|
|
private static string EmbyServiceName = "Emby";
|
|
|
|
public override double GetDefaultPrimaryImageAspectRatio()
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2018-12-27 21:43:48 +00:00
|
|
|
var serviceName = ServiceName;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2018-12-27 21:43:48 +00:00
|
|
|
if (string.Equals(serviceName, EmbyServiceName, StringComparison.OrdinalIgnoreCase) || string.Equals(serviceName, "Next Pvr", StringComparison.OrdinalIgnoreCase))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2019-01-07 21:10:11 +00:00
|
|
|
return 2.0 / 3;
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-07 21:10:11 +00:00
|
|
|
return 16.0 / 9;
|
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]
|
2019-01-13 20:31:14 +00:00
|
|
|
public bool IsSports => Tags.Contains("Sports", StringComparer.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]
|
2019-01-13 20:31:14 +00:00
|
|
|
public bool IsLive => Tags.Contains("Live", StringComparer.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]
|
2019-01-13 20:31:14 +00:00
|
|
|
public bool IsNews => Tags.Contains("News", StringComparer.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]
|
2019-01-13 20:31:14 +00:00
|
|
|
public bool IsKids => Tags.Contains("Kids", StringComparer.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]
|
2019-01-13 20:31:14 +00:00
|
|
|
public bool IsPremiere => Tags.Contains("Premiere", StringComparer.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
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
//[JsonIgnore]
|
2020-06-14 09:11:11 +00:00
|
|
|
// public override string MediaType
|
2018-12-27 23:27:57 +00:00
|
|
|
//{
|
|
|
|
// get
|
|
|
|
// {
|
|
|
|
// return ChannelType == ChannelType.TV ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2018-12-27 23:27:57 +00:00
|
|
|
public override bool SupportsPeople
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// Optimization
|
|
|
|
if (IsNews || IsSports)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.SupportsPeople;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2019-01-13 20:31:14 +00:00
|
|
|
public override bool SupportsAncestors => false;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (listings != null)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:25:32 +00:00
|
|
|
public string SeriesName { get; set; }
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
}
|