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;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-05-20 17:07:53 +00:00
|
|
|
using Jellyfin.Data.Entities;
|
2020-05-13 02:10:35 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Controller.Dto;
|
2019-01-13 19:25:32 +00:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Model.Providers;
|
2019-01-13 19:25:32 +00:00
|
|
|
using MediaBrowser.Model.Querying;
|
2020-06-11 22:28:49 +00:00
|
|
|
using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities.TV
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Class Series.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
|
|
|
public class Series : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>, IMetadataContainer
|
|
|
|
{
|
|
|
|
public Series()
|
|
|
|
{
|
2019-03-07 14:54:30 +00:00
|
|
|
RemoteTrailers = Array.Empty<MediaUrl>();
|
2018-12-27 21:43:48 +00:00
|
|
|
LocalTrailerIds = Array.Empty<Guid>();
|
|
|
|
RemoteTrailerIds = Array.Empty<Guid>();
|
|
|
|
AirDays = Array.Empty<DayOfWeek>();
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public DayOfWeek[] AirDays { get; set; }
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public string AirTime { get; set; }
|
|
|
|
|
2019-10-15 15:49:49 +00:00
|
|
|
[JsonIgnore]
|
2019-01-13 20:31:14 +00:00
|
|
|
public override bool SupportsAddingToPlaylist => true;
|
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 bool IsPreSorted => true;
|
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 bool SupportsDateLastMediaAdded => true;
|
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 bool SupportsInheritedParentImages => false;
|
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 bool SupportsPeople => true;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2019-09-02 06:19:29 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
public IReadOnlyList<Guid> LocalTrailerIds { get; set; }
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2021-05-13 13:32:02 +00:00
|
|
|
/// Gets or sets the display order.
|
2018-12-27 23:27:57 +00:00
|
|
|
/// </summary>
|
2021-05-13 13:32:02 +00:00
|
|
|
/// <remarks>
|
|
|
|
/// Valid options are airdate, dvd or absolute.
|
|
|
|
/// </remarks>
|
2018-12-27 23:27:57 +00:00
|
|
|
public string DisplayOrder { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the status.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The status.</value>
|
|
|
|
public SeriesStatus? Status { get; set; }
|
|
|
|
|
2021-08-14 03:34:36 +00:00
|
|
|
[JsonIgnore]
|
|
|
|
public override bool StopRefreshIfLocalMetadataFound => false;
|
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
public override double GetDefaultPrimaryImageAspectRatio()
|
|
|
|
{
|
|
|
|
double value = 2;
|
|
|
|
value /= 3;
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string CreatePresentationUniqueKey()
|
|
|
|
{
|
|
|
|
if (LibraryManager.GetLibraryOptions(this).EnableAutomaticSeriesGrouping)
|
|
|
|
{
|
|
|
|
var userdatakeys = GetUserDataKeys();
|
|
|
|
|
|
|
|
if (userdatakeys.Count > 1)
|
|
|
|
{
|
|
|
|
return AddLibrariesToPresentationUniqueKey(userdatakeys[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.CreatePresentationUniqueKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
private string AddLibrariesToPresentationUniqueKey(string key)
|
|
|
|
{
|
|
|
|
var lang = GetPreferredMetadataLanguage();
|
|
|
|
if (!string.IsNullOrEmpty(lang))
|
|
|
|
{
|
|
|
|
key += "-" + lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
var folders = LibraryManager.GetCollectionFolders(this)
|
2019-02-28 22:22:57 +00:00
|
|
|
.Select(i => i.Id.ToString("N", CultureInfo.InvariantCulture))
|
2018-12-27 23:27:57 +00:00
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
if (folders.Length == 0)
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:39:18 +00:00
|
|
|
return key + "-" + string.Join('-', folders);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static string GetUniqueSeriesKey(BaseItem series)
|
|
|
|
{
|
|
|
|
return series.GetPresentationUniqueKey();
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public override int GetChildCount(User user)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var seriesKey = GetUniqueSeriesKey(this);
|
|
|
|
|
|
|
|
var result = LibraryManager.GetCount(new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
AncestorWithPresentationUniqueKey = null,
|
|
|
|
SeriesPresentationUniqueKey = seriesKey,
|
2020-05-13 02:10:35 +00:00
|
|
|
IncludeItemTypes = new[] { nameof(Season) },
|
2018-12-27 23:27:57 +00:00
|
|
|
IsVirtualItem = false,
|
|
|
|
Limit = 0,
|
2019-01-13 20:37:13 +00:00
|
|
|
DtoOptions = new DtoOptions(false)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
EnableImages = false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public override int GetRecursiveChildCount(User user)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var seriesKey = GetUniqueSeriesKey(this);
|
|
|
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
AncestorWithPresentationUniqueKey = null,
|
|
|
|
SeriesPresentationUniqueKey = seriesKey,
|
2019-01-13 20:37:13 +00:00
|
|
|
DtoOptions = new DtoOptions(false)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
EnableImages = false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (query.IncludeItemTypes.Length == 0)
|
|
|
|
{
|
2020-10-17 14:19:57 +00:00
|
|
|
query.IncludeItemTypes = new[] { nameof(Episode) };
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
query.IsVirtualItem = false;
|
|
|
|
query.Limit = 0;
|
|
|
|
var totalRecordCount = LibraryManager.GetCount(query);
|
|
|
|
|
|
|
|
return totalRecordCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the user data key.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
public override List<string> GetUserDataKeys()
|
|
|
|
{
|
|
|
|
var list = base.GetUserDataKeys();
|
|
|
|
|
2021-04-21 20:25:08 +00:00
|
|
|
if (this.TryGetProviderId(MetadataProvider.Imdb, out var key))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
list.Insert(0, key);
|
|
|
|
}
|
|
|
|
|
2021-04-21 20:25:08 +00:00
|
|
|
if (this.TryGetProviderId(MetadataProvider.Tvdb, out key))
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
list.Insert(0, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return GetSeasons(user, new DtoOptions(true));
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public List<BaseItem> GetSeasons(User user, DtoOptions options)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
DtoOptions = options
|
|
|
|
};
|
|
|
|
|
|
|
|
SetSeasonQueryOptions(query, user);
|
|
|
|
|
|
|
|
return LibraryManager.GetItemList(query);
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
private void SetSeasonQueryOptions(InternalItemsQuery query, User user)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var seriesKey = GetUniqueSeriesKey(this);
|
|
|
|
|
|
|
|
query.AncestorWithPresentationUniqueKey = null;
|
|
|
|
query.SeriesPresentationUniqueKey = seriesKey;
|
2020-10-17 14:19:57 +00:00
|
|
|
query.IncludeItemTypes = new[] { nameof(Season) };
|
2021-04-21 20:25:08 +00:00
|
|
|
query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) };
|
2018-12-27 23:27:57 +00:00
|
|
|
|
2020-05-13 02:10:35 +00:00
|
|
|
if (user != null && !user.DisplayMissingEpisodes)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2020-05-13 02:10:35 +00:00
|
|
|
query.IsMissing = false;
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
|
|
|
|
{
|
|
|
|
var user = query.User;
|
|
|
|
|
|
|
|
if (query.Recursive)
|
|
|
|
{
|
|
|
|
var seriesKey = GetUniqueSeriesKey(this);
|
|
|
|
|
|
|
|
query.AncestorWithPresentationUniqueKey = null;
|
|
|
|
query.SeriesPresentationUniqueKey = seriesKey;
|
2019-10-20 14:08:40 +00:00
|
|
|
if (query.OrderBy.Count == 0)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2021-04-21 20:25:08 +00:00
|
|
|
query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) };
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
2019-10-20 14:08:40 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
if (query.IncludeItemTypes.Length == 0)
|
|
|
|
{
|
2020-10-17 14:19:57 +00:00
|
|
|
query.IncludeItemTypes = new[] { nameof(Episode), nameof(Season) };
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
2019-10-20 14:08:40 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
query.IsVirtualItem = false;
|
|
|
|
return LibraryManager.GetItemsResult(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSeasonQueryOptions(query, user);
|
|
|
|
|
|
|
|
return LibraryManager.GetItemsResult(query);
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public IEnumerable<BaseItem> GetEpisodes(User user, DtoOptions options)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var seriesKey = GetUniqueSeriesKey(this);
|
|
|
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
AncestorWithPresentationUniqueKey = null,
|
|
|
|
SeriesPresentationUniqueKey = seriesKey,
|
2020-10-17 14:19:57 +00:00
|
|
|
IncludeItemTypes = new[] { nameof(Episode), nameof(Season) },
|
2021-04-21 20:25:08 +00:00
|
|
|
OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },
|
2018-12-27 23:27:57 +00:00
|
|
|
DtoOptions = options
|
|
|
|
};
|
2020-05-13 02:10:35 +00:00
|
|
|
|
|
|
|
if (!user.DisplayMissingEpisodes)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
query.IsMissing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var allItems = LibraryManager.GetItemList(query);
|
|
|
|
|
|
|
|
var allSeriesEpisodes = allItems.OfType<Episode>().ToList();
|
|
|
|
|
|
|
|
var allEpisodes = allItems.OfType<Season>()
|
|
|
|
.SelectMany(i => i.GetEpisodes(this, user, allSeriesEpisodes, options))
|
|
|
|
.Reverse();
|
|
|
|
|
|
|
|
// Specials could appear twice based on above - once in season 0, once in the aired season
|
|
|
|
// This depends on settings for that series
|
|
|
|
// When this happens, remove the duplicate from season 0
|
|
|
|
|
2019-02-02 11:27:06 +00:00
|
|
|
return allEpisodes.GroupBy(i => i.Id).Select(x => x.First()).Reverse();
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
// Refresh bottom up, children first, then the boxset
|
|
|
|
// By then hopefully the movies within will have Tmdb collection values
|
|
|
|
var items = GetRecursiveChildren();
|
|
|
|
|
|
|
|
var totalItems = items.Count;
|
|
|
|
var numComplete = 0;
|
|
|
|
|
|
|
|
// Refresh seasons
|
|
|
|
foreach (var item in items)
|
|
|
|
{
|
2021-08-28 22:32:50 +00:00
|
|
|
if (item is not Season)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
if (refreshOptions.RefreshItem(item))
|
|
|
|
{
|
|
|
|
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
numComplete++;
|
|
|
|
double percent = numComplete;
|
|
|
|
percent /= totalItems;
|
|
|
|
progress.Report(percent * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh episodes and other children
|
|
|
|
foreach (var item in items)
|
|
|
|
{
|
2020-05-13 02:10:35 +00:00
|
|
|
if (item is Season)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
2021-05-05 11:37:36 +00:00
|
|
|
bool skipItem = item is Episode episode
|
2018-12-27 23:27:57 +00:00
|
|
|
&& refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh
|
|
|
|
&& !refreshOptions.ReplaceAllMetadata
|
|
|
|
&& episode.IsMissingEpisode
|
|
|
|
&& episode.LocationType == LocationType.Virtual
|
|
|
|
&& episode.PremiereDate.HasValue
|
2021-05-05 11:37:36 +00:00
|
|
|
&& (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
if (!skipItem)
|
|
|
|
{
|
|
|
|
if (refreshOptions.RefreshItem(item))
|
|
|
|
{
|
|
|
|
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
numComplete++;
|
|
|
|
double percent = numComplete;
|
|
|
|
percent /= totalItems;
|
|
|
|
progress.Report(percent * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshOptions = new MetadataRefreshOptions(refreshOptions);
|
|
|
|
await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public List<BaseItem> GetSeasonEpisodes(Season parentSeason, User user, DtoOptions options)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var queryFromSeries = ConfigurationManager.Configuration.DisplaySpecialsWithinSeasons;
|
|
|
|
|
|
|
|
// add optimization when this setting is not enabled
|
|
|
|
var seriesKey = queryFromSeries ?
|
|
|
|
GetUniqueSeriesKey(this) :
|
|
|
|
GetUniqueSeriesKey(parentSeason);
|
|
|
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
{
|
|
|
|
AncestorWithPresentationUniqueKey = queryFromSeries ? null : seriesKey,
|
|
|
|
SeriesPresentationUniqueKey = queryFromSeries ? seriesKey : null,
|
2020-10-17 14:19:57 +00:00
|
|
|
IncludeItemTypes = new[] { nameof(Episode) },
|
2021-04-21 20:25:08 +00:00
|
|
|
OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) },
|
2018-12-27 23:27:57 +00:00
|
|
|
DtoOptions = options
|
|
|
|
};
|
|
|
|
if (user != null)
|
|
|
|
{
|
2020-05-13 02:10:35 +00:00
|
|
|
if (!user.DisplayMissingEpisodes)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
query.IsMissing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var allItems = LibraryManager.GetItemList(query);
|
|
|
|
|
|
|
|
return GetSeasonEpisodes(parentSeason, user, allItems, options);
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public List<BaseItem> GetSeasonEpisodes(Season parentSeason, User user, IEnumerable<BaseItem> allSeriesEpisodes, DtoOptions options)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
if (allSeriesEpisodes == null)
|
|
|
|
{
|
|
|
|
return GetSeasonEpisodes(parentSeason, user, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
var episodes = FilterEpisodesBySeason(allSeriesEpisodes, parentSeason, ConfigurationManager.Configuration.DisplaySpecialsWithinSeasons);
|
|
|
|
|
|
|
|
var sortBy = (parentSeason.IndexNumber ?? -1) == 0 ? ItemSortBy.SortName : ItemSortBy.AiredEpisodeOrder;
|
|
|
|
|
|
|
|
return LibraryManager.Sort(episodes, user, new[] { sortBy }, SortOrder.Ascending).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Filters the episodes by season.
|
|
|
|
/// </summary>
|
2021-08-14 03:34:36 +00:00
|
|
|
/// <param name="episodes">The episodes.</param>
|
|
|
|
/// <param name="parentSeason">The season.</param>
|
|
|
|
/// <param name="includeSpecials"><c>true</c> to include special, <c>false</c> to not.</param>
|
|
|
|
/// <returns>The set of episodes.</returns>
|
2018-12-27 23:27:57 +00:00
|
|
|
public static IEnumerable<BaseItem> FilterEpisodesBySeason(IEnumerable<BaseItem> episodes, Season parentSeason, bool includeSpecials)
|
|
|
|
{
|
|
|
|
var seasonNumber = parentSeason.IndexNumber;
|
|
|
|
var seasonPresentationKey = GetUniqueSeriesKey(parentSeason);
|
|
|
|
|
|
|
|
var supportSpecialsInSeason = includeSpecials && seasonNumber.HasValue && seasonNumber.Value != 0;
|
|
|
|
|
|
|
|
return episodes.Where(episode =>
|
|
|
|
{
|
|
|
|
var episodeItem = (Episode)episode;
|
|
|
|
|
|
|
|
var currentSeasonNumber = supportSpecialsInSeason ? episodeItem.AiredSeasonNumber : episode.ParentIndexNumber;
|
|
|
|
if (currentSeasonNumber.HasValue && seasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber.Value)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!currentSeasonNumber.HasValue && !seasonNumber.HasValue && parentSeason.LocationType == LocationType.Virtual)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var season = episodeItem.Season;
|
|
|
|
return season != null && string.Equals(GetUniqueSeriesKey(season), seasonPresentationKey, StringComparison.OrdinalIgnoreCase);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Filters the episodes by season.
|
|
|
|
/// </summary>
|
2021-08-14 03:34:36 +00:00
|
|
|
/// <param name="episodes">The episodes.</param>
|
|
|
|
/// <param name="seasonNumber">The season.</param>
|
|
|
|
/// <param name="includeSpecials"><c>true</c> to include special, <c>false</c> to not.</param>
|
|
|
|
/// <returns>The set of episodes.</returns>
|
2018-12-27 23:27:57 +00:00
|
|
|
public static IEnumerable<Episode> FilterEpisodesBySeason(IEnumerable<Episode> episodes, int seasonNumber, bool includeSpecials)
|
|
|
|
{
|
|
|
|
if (!includeSpecials || seasonNumber < 1)
|
|
|
|
{
|
|
|
|
return episodes.Where(i => (i.ParentIndexNumber ?? -1) == seasonNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
return episodes.Where(i =>
|
|
|
|
{
|
|
|
|
var episode = i;
|
|
|
|
|
|
|
|
if (episode != null)
|
|
|
|
{
|
|
|
|
var currentSeasonNumber = episode.AiredSeasonNumber;
|
|
|
|
|
|
|
|
return currentSeasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
protected override bool GetBlockUnratedValue(User user)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
2020-12-13 15:15:26 +00:00
|
|
|
return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Series);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override UnratedItem GetBlockUnratedType()
|
|
|
|
{
|
|
|
|
return UnratedItem.Series;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SeriesInfo GetLookupInfo()
|
|
|
|
{
|
|
|
|
var info = GetItemLookupInfo<SeriesInfo>();
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
|
|
|
|
{
|
|
|
|
var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
|
|
|
|
|
|
|
|
if (!ProductionYear.HasValue)
|
|
|
|
{
|
|
|
|
var info = LibraryManager.ParseName(Name);
|
|
|
|
|
|
|
|
var yearInName = info.Year;
|
|
|
|
|
|
|
|
if (yearInName.HasValue)
|
|
|
|
{
|
|
|
|
ProductionYear = yearInName;
|
|
|
|
hasChanges = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasChanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
list.Add(new ExternalUrl
|
|
|
|
{
|
|
|
|
Name = "Trakt",
|
2020-08-07 17:26:28 +00:00
|
|
|
Url = string.Format(CultureInfo.InvariantCulture, "https://trakt.tv/shows/{0}", imdbId)
|
2018-12-27 23:27:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|