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

250 lines
7.0 KiB
C#
Raw Normal View History

using System;
2018-12-27 23:27:57 +00:00
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Providers;
2018-12-27 23:27:57 +00:00
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Querying;
2018-12-27 23:27:57 +00:00
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Users;
2018-12-27 23:27:57 +00:00
namespace MediaBrowser.Controller.Entities.TV
{
/// <summary>
/// Class Season
/// </summary>
public class Season : Folder, IHasSeries, IHasLookupInfo<SeasonInfo>
{
[IgnoreDataMember]
public override bool SupportsAddingToPlaylist => true;
2018-12-27 23:27:57 +00:00
[IgnoreDataMember]
public override bool IsPreSorted => true;
2018-12-27 23:27:57 +00:00
[IgnoreDataMember]
public override bool SupportsDateLastMediaAdded => false;
2018-12-27 23:27:57 +00:00
[IgnoreDataMember]
public override bool SupportsPeople => true;
2018-12-27 23:27:57 +00:00
[IgnoreDataMember]
public override bool SupportsInheritedParentImages => true;
2018-12-27 23:27:57 +00:00
[IgnoreDataMember]
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)
{
list.InsertRange(0, series.GetUserDataKeys().Select(i => i + (IndexNumber ?? 0).ToString("000")));
}
return list;
}
public override int GetChildCount(User user)
{
var result = GetChildren(user, true).Count;
return result;
}
/// <summary>
/// This Episode's Series Instance
/// </summary>
/// <value>The series.</value>
[IgnoreDataMember]
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();
}
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
}
}
[IgnoreDataMember]
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");
}
}
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") : Name;
}
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>
public List<BaseItem> GetEpisodes(User user, DtoOptions options)
{
return GetEpisodes(Series, user, options);
}
public List<BaseItem> GetEpisodes(Series series, User user, DtoOptions options)
{
return GetEpisodes(series, user, null, options);
}
public List<BaseItem> GetEpisodes(Series series, User user, IEnumerable<Episode> allSeriesEpisodes, DtoOptions options)
{
return series.GetSeasonEpisodes(this, user, allSeriesEpisodes, options);
}
public List<BaseItem> GetEpisodes()
{
return Series.GetSeasonEpisodes(this, null, null, new DtoOptions(true));
}
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
{
return GetEpisodes(user, new DtoOptions(true));
}
protected override bool GetBlockUnratedValue(UserPolicy config)
{
// Don't block. Let either the entire series rating or episode rating determine it
return false;
}
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.Series;
}
[IgnoreDataMember]
public string SeriesPresentationUniqueKey { get; set; }
[IgnoreDataMember]
public string SeriesName { get; set; }
[IgnoreDataMember]
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>();
2018-12-27 21:43:48 +00:00
return series == null ? Guid.Empty : series.Id;
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
/// </summary>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
{
var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path))
{
IndexNumber = IndexNumber ?? LibraryManager.GetSeasonNumberFromPath(Path);
// If a change was made record it
if (IndexNumber.HasValue)
{
hasChanges = true;
}
}
return hasChanges;
}
}
}