jellyfin/MediaBrowser.Controller/Entities/TV/Season.cs

264 lines
7.3 KiB
C#
Raw Normal View History

#nullable disable
#pragma warning disable CS1591
using System;
2018-12-27 23:27:57 +00:00
using System.Collections.Generic;
2021-04-21 20:25:08 +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-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;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Querying;
2018-12-27 23:27:57 +00:00
namespace MediaBrowser.Controller.Entities.TV
{
/// <summary>
/// Class Season.
2018-12-27 23:27:57 +00:00
/// </summary>
public class Season : Folder, IHasSeries, IHasLookupInfo<SeasonInfo>
{
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override bool SupportsAddingToPlaylist => true;
2018-12-27 23:27:57 +00:00
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override bool IsPreSorted => true;
2018-12-27 23:27:57 +00:00
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override bool SupportsDateLastMediaAdded => false;
2018-12-27 23:27:57 +00:00
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override bool SupportsPeople => true;
2018-12-27 23:27:57 +00:00
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override bool SupportsInheritedParentImages => true;
2018-12-27 23:27:57 +00:00
2019-10-15 15:49:49 +00:00
[JsonIgnore]
public override Guid DisplayParentId => SeriesId;
2018-12-27 23:27:57 +00:00
public override double GetDefaultPrimaryImageAspectRatio()
{
double value = 2;
value /= 3;
return value;
}
public string FindSeriesSortName()
{
var series = Series;
return series == null ? SeriesName : series.SortName;
}
public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();
var series = Series;
if (series != null)
{
2021-04-21 20:25:08 +00:00
var newList = series.GetUserDataKeys();
var suffix = (IndexNumber ?? 0).ToString("000", CultureInfo.InvariantCulture);
for (int i = 0; i < newList.Count; i++)
{
newList[i] = newList[i] + suffix;
}
newList.AddRange(list);
list = newList;
2018-12-27 23:27:57 +00:00
}
return list;
}
2020-05-20 17:07:53 +00:00
public override int GetChildCount(User user)
2018-12-27 23:27:57 +00:00
{
var result = GetChildren(user, true).Count;
return result;
}
/// <summary>
/// Gets this Episode's Series Instance.
2018-12-27 23:27:57 +00:00
/// </summary>
/// <value>The series.</value>
2019-10-15 15:49:49 +00:00
[JsonIgnore]
2018-12-27 23:27:57 +00:00
public Series Series
{
get
{
var seriesId = SeriesId;
2018-12-27 21:43:48 +00:00
if (seriesId == Guid.Empty)
{
2018-12-27 23:27:57 +00:00
seriesId = FindSeriesId();
}
2020-06-15 21:43:52 +00:00
2018-12-27 21:43:48 +00:00
return seriesId == Guid.Empty ? null : (LibraryManager.GetItemById(seriesId) as Series);
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 string SeriesPath
{
get
{
var series = Series;
if (series != null)
{
return series.Path;
}
return System.IO.Path.GetDirectoryName(Path);
2018-12-27 23:27:57 +00:00
}
}
public override string CreatePresentationUniqueKey()
{
if (IndexNumber.HasValue)
{
var series = Series;
if (series != null)
{
return series.PresentationUniqueKey + "-" + (IndexNumber ?? 0).ToString("000", CultureInfo.InvariantCulture);
2018-12-27 23:27:57 +00:00
}
}
return base.CreatePresentationUniqueKey();
}
/// <summary>
/// Creates the name of the sort.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateSortName()
{
return IndexNumber != null ? IndexNumber.Value.ToString("0000", CultureInfo.InvariantCulture) : Name;
2018-12-27 23:27:57 +00:00
}
protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
{
if (query.User == null)
{
return base.GetItemsInternal(query);
}
var user = query.User;
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
var items = GetEpisodes(user, query.DtoOptions).Where(filter);
return PostFilterAndSort(items, query, false);
}
/// <summary>
/// Gets the episodes.
/// </summary>
2020-05-20 17:07:53 +00:00
public List<BaseItem> GetEpisodes(User user, DtoOptions options)
2018-12-27 23:27:57 +00:00
{
return GetEpisodes(Series, user, options);
}
2020-05-20 17:07:53 +00:00
public List<BaseItem> GetEpisodes(Series series, User user, DtoOptions options)
2018-12-27 23:27:57 +00:00
{
return GetEpisodes(series, user, null, options);
}
2020-05-20 17:07:53 +00:00
public List<BaseItem> GetEpisodes(Series series, User user, IEnumerable<Episode> allSeriesEpisodes, DtoOptions options)
2018-12-27 23:27:57 +00:00
{
return series.GetSeasonEpisodes(this, user, allSeriesEpisodes, options);
}
public List<BaseItem> GetEpisodes()
{
return Series.GetSeasonEpisodes(this, null, null, new DtoOptions(true));
}
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 GetEpisodes(user, new DtoOptions(true));
}
2020-05-27 02:43:03 +00:00
protected override bool GetBlockUnratedValue(User user)
2018-12-27 23:27:57 +00:00
{
// Don't block. Let either the entire series rating or episode rating determine it
return false;
}
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.Series;
}
2019-10-15 15:49:49 +00:00
[JsonIgnore]
2018-12-27 23:27:57 +00:00
public string SeriesPresentationUniqueKey { get; set; }
2019-10-15 15:49:49 +00:00
[JsonIgnore]
2018-12-27 23:27:57 +00:00
public string SeriesName { get; set; }
2019-10-15 15:49:49 +00:00
[JsonIgnore]
2018-12-27 23:27:57 +00:00
public Guid SeriesId { get; set; }
public string FindSeriesPresentationUniqueKey()
{
var series = Series;
return series == null ? null : series.PresentationUniqueKey;
}
public string FindSeriesName()
{
var series = Series;
return series == null ? SeriesName : series.Name;
}
public Guid FindSeriesId()
{
var series = FindParent<Series>();
2020-05-13 02:10:35 +00:00
return series?.Id ?? Guid.Empty;
2018-12-27 23:27:57 +00:00
}
/// <summary>
/// Gets the lookup information.
/// </summary>
/// <returns>SeasonInfo.</returns>
public SeasonInfo GetLookupInfo()
{
var id = GetItemLookupInfo<SeasonInfo>();
var series = Series;
if (series != null)
{
id.SeriesProviderIds = series.ProviderIds;
}
return id;
}
/// <summary>
/// This is called before any metadata refresh and returns true or false indicating if changes were made.
2018-12-27 23:27:57 +00:00
/// </summary>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
2018-12-27 23:27:57 +00:00
{
var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
2018-12-27 23:27:57 +00:00
if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path))
{
2020-05-13 02:10:35 +00:00
IndexNumber ??= LibraryManager.GetSeasonNumberFromPath(Path);
2018-12-27 23:27:57 +00:00
// If a change was made record it
if (IndexNumber.HasValue)
{
hasChanges = true;
}
}
return hasChanges;
}
}
}