jellyfin-server/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs

277 lines
8.4 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
2018-12-27 23:27:57 +00:00
using System.Collections.Generic;
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;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
2018-12-27 23:27:57 +00:00
using MediaBrowser.Model.Entities;
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
{
return 2.0 / 3;
2018-12-27 23:27:57 +00:00
}
else
{
return 16.0 / 9;
2018-12-27 23:27:57 +00:00
}
}
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override SourceType SourceType => SourceType.LiveTV;
2018-12-27 23:27:57 +00:00
/// <summary>
/// The start date of the program, in UTC.
/// </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>
/// Gets or sets a value indicating whether this instance is sports.
/// </summary>
/// <value><c>true</c> if this instance is sports; otherwise, <c>false</c>.</value>
2019-10-15 15:49:49 +00:00
[JsonIgnore]
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>
/// Gets or sets a value indicating whether this instance is live.
/// </summary>
/// <value><c>true</c> if this instance is live; otherwise, <c>false</c>.</value>
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public bool IsLive => Tags.Contains("Live", StringComparer.OrdinalIgnoreCase);
2018-12-27 23:27:57 +00:00
/// <summary>
/// Gets or sets a value indicating whether this instance is news.
/// </summary>
/// <value><c>true</c> if this instance is news; otherwise, <c>false</c>.</value>
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public bool IsNews => Tags.Contains("News", StringComparer.OrdinalIgnoreCase);
2018-12-27 23:27:57 +00:00
/// <summary>
/// Gets or sets a value indicating whether this instance is kids.
/// </summary>
/// <value><c>true</c> if this instance is kids; otherwise, <c>false</c>.</value>
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public bool IsKids => Tags.Contains("Kids", StringComparer.OrdinalIgnoreCase);
2018-12-27 23:27:57 +00:00
/// <summary>
/// Gets or sets a value indicating whether this instance is premiere.
/// </summary>
/// <value><c>true</c> if this instance is premiere; otherwise, <c>false</c>.</value>
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public bool IsPremiere => Tags.Contains("Premiere", StringComparer.OrdinalIgnoreCase);
2018-12-27 23:27:57 +00:00
/// <summary>
/// Returns the folder containing the item.
/// 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]
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)
{
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]
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;
}
public string SeriesName { get; set; }
2018-12-27 23:27:57 +00:00
}
}