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

336 lines
9.2 KiB
C#
Raw Normal View History

2014-12-18 21:20:07 -07:00
using MediaBrowser.Controller.Providers;
2014-02-06 20:10:13 -07:00
using MediaBrowser.Model.Configuration;
2014-02-10 11:39:41 -07:00
using MediaBrowser.Model.Entities;
using System;
2013-10-26 15:01:21 -07:00
using System.Collections.Generic;
2013-02-20 18:33:05 -07:00
using System.Linq;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities.TV
{
/// <summary>
/// Class Episode
/// </summary>
public class Episode : Video, IHasTrailers, IHasLookupInfo<EpisodeInfo>, IHasSeries
{
public Episode()
{
RemoteTrailers = new List<MediaUrl>();
LocalTrailerIds = new List<Guid>();
RemoteTrailerIds = new List<Guid>();
}
public List<Guid> LocalTrailerIds { get; set; }
public List<Guid> RemoteTrailerIds { get; set; }
public List<MediaUrl> RemoteTrailers { get; set; }
2016-07-04 13:11:30 -07:00
/// <summary>
/// Gets the season in which it aired.
/// </summary>
/// <value>The aired season.</value>
public int? AirsBeforeSeasonNumber { get; set; }
public int? AirsAfterSeasonNumber { get; set; }
public int? AirsBeforeEpisodeNumber { get; set; }
2013-11-15 14:31:33 -07:00
2013-12-08 11:07:45 -07:00
/// <summary>
/// Gets or sets the DVD season number.
/// </summary>
/// <value>The DVD season number.</value>
public int? DvdSeasonNumber { get; set; }
/// <summary>
/// Gets or sets the DVD episode number.
/// </summary>
/// <value>The DVD episode number.</value>
public float? DvdEpisodeNumber { get; set; }
2013-12-08 11:07:45 -07:00
/// <summary>
/// Gets or sets the absolute episode number.
/// </summary>
/// <value>The absolute episode number.</value>
public int? AbsoluteEpisodeNumber { get; set; }
/// <summary>
/// This is the ending episode number for double episodes.
/// </summary>
/// <value>The index number.</value>
public int? IndexNumberEnd { get; set; }
2014-02-06 20:10:13 -07:00
2015-01-28 14:29:02 -07:00
[IgnoreDataMember]
protected override bool SupportsOwnedItems
{
get
{
return IsStacked || MediaSourceCount > 1;
}
}
[IgnoreDataMember]
public int? AiredSeasonNumber
{
get
{
2016-05-01 22:32:04 -07:00
return AirsAfterSeasonNumber ?? AirsBeforeSeasonNumber ?? ParentIndexNumber;
}
}
2014-08-28 21:06:30 -07:00
[IgnoreDataMember]
public override Folder LatestItemsIndexContainer
{
get
{
return Series;
}
}
2014-10-23 21:54:35 -07:00
[IgnoreDataMember]
2016-04-08 21:16:53 -07:00
public override Guid? DisplayParentId
2014-10-23 21:54:35 -07:00
{
get
{
2016-04-08 21:16:53 -07:00
return SeasonId;
2014-10-23 21:54:35 -07:00
}
}
2016-04-30 16:05:21 -07:00
[IgnoreDataMember]
protected override bool EnableDefaultVideoUserDataKeys
2013-02-20 18:33:05 -07:00
{
2016-04-30 16:05:21 -07:00
get
{
return false;
}
}
2014-02-06 08:58:49 -07:00
2016-04-30 16:05:21 -07:00
public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();
var series = Series;
2014-02-06 08:58:49 -07:00
if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
2013-02-20 18:33:05 -07:00
{
2016-06-03 17:15:14 -07:00
var seriesUserDataKeys = series.GetUserDataKeys();
var take = seriesUserDataKeys.Count;
if (seriesUserDataKeys.Count > 1)
{
take--;
}
list.InsertRange(0, seriesUserDataKeys.Take(take).Select(i => i + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000")));
2013-02-20 18:33:05 -07:00
}
2016-04-30 16:05:21 -07:00
return list;
2013-02-20 18:33:05 -07:00
}
/// <summary>
/// This Episode's Series Instance
/// </summary>
/// <value>The series.</value>
[IgnoreDataMember]
public Series Series
{
get { return FindParent<Series>(); }
2013-02-20 18:33:05 -07:00
}
[IgnoreDataMember]
public Season Season
{
2014-10-15 20:26:39 -07:00
get
{
var season = FindParent<Season>();
// Episodes directly in series folder
if (season == null)
{
2014-10-23 21:54:35 -07:00
var series = Series;
2014-10-15 20:26:39 -07:00
2015-07-31 13:38:08 -07:00
if (series != null && ParentIndexNumber.HasValue)
2014-10-15 20:26:39 -07:00
{
var findNumber = ParentIndexNumber.Value;
season = series.Children
.OfType<Season>()
.FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == findNumber);
}
}
return season;
}
}
2014-12-22 20:58:14 -07:00
[IgnoreDataMember]
public bool IsInSeasonFolder
{
get
{
return FindParent<Season>() != null;
}
}
2014-02-08 13:02:35 -07:00
[IgnoreDataMember]
2016-07-04 13:11:30 -07:00
public string SeriesName { get; set; }
[IgnoreDataMember]
public string SeasonName { get; set; }
public string FindSeasonName()
{
var season = Season;
return season == null ? SeasonName : season.Name;
}
public string FindSeriesName()
{
var series = Series;
return series == null ? SeriesName : series.Name;
2016-07-04 22:40:18 -07:00
}
public Guid? FindSeasonId()
{
var season = Season;
return season == null ? (Guid?)null : season.Id;
2014-02-08 13:02:35 -07:00
}
/// <summary>
/// Creates the name of the sort.
/// </summary>
/// <returns>System.String.</returns>
protected override string CreateSortName()
{
2016-03-31 14:14:03 -07:00
return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("000 - ") : "")
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
}
/// <summary>
/// Determines whether [contains episode number] [the specified number].
/// </summary>
/// <param name="number">The number.</param>
/// <returns><c>true</c> if [contains episode number] [the specified number]; otherwise, <c>false</c>.</returns>
public bool ContainsEpisodeNumber(int number)
{
if (IndexNumber.HasValue)
{
if (IndexNumberEnd.HasValue)
{
return number >= IndexNumber.Value && number <= IndexNumberEnd.Value;
}
return IndexNumber.Value == number;
}
return false;
}
2013-10-26 15:01:21 -07:00
2014-08-14 06:24:30 -07:00
[IgnoreDataMember]
public override bool SupportsRemoteImageDownloading
{
get
{
if (IsMissingEpisode)
{
return false;
}
return true;
}
}
2013-11-12 08:36:08 -07:00
[IgnoreDataMember]
2013-10-26 15:01:21 -07:00
public bool IsMissingEpisode
{
get
{
2014-03-03 21:53:48 -07:00
return LocationType == LocationType.Virtual && !IsUnaired;
2013-10-26 15:01:21 -07:00
}
}
2013-11-12 08:36:08 -07:00
[IgnoreDataMember]
2013-10-26 15:40:53 -07:00
public bool IsVirtualUnaired
{
2014-02-10 13:11:46 -07:00
get { return LocationType == LocationType.Virtual && IsUnaired; }
2013-10-26 15:01:21 -07:00
}
[IgnoreDataMember]
2016-07-04 23:01:31 -07:00
public Guid? SeasonId { get; set; }
public Guid? SeriesId { get; set; }
public Guid? FindSeriesId()
{
var series = Series;
return series == null ? (Guid?)null : series.Id;
}
2015-10-29 06:28:05 -07:00
public override IEnumerable<Guid> GetAncestorIds()
{
var list = base.GetAncestorIds().ToList();
var seasonId = SeasonId;
if (seasonId.HasValue && !list.Contains(seasonId.Value))
{
list.Add(seasonId.Value);
}
return list;
}
public override IEnumerable<string> GetDeletePaths()
{
return new[] { Path };
}
2013-12-26 09:53:23 -07:00
2015-11-06 08:02:22 -07:00
public override UnratedItem GetBlockUnratedType()
2013-12-26 09:53:23 -07:00
{
2015-11-06 08:02:22 -07:00
return UnratedItem.Series;
2013-12-26 09:53:23 -07:00
}
2014-02-06 20:10:13 -07:00
public EpisodeInfo GetLookupInfo()
{
var id = GetItemLookupInfo<EpisodeInfo>();
var series = Series;
if (series != null)
{
id.SeriesProviderIds = series.ProviderIds;
2014-02-27 21:49:02 -07:00
id.AnimeSeriesIndex = series.AnimeSeriesIndex;
2014-02-06 20:10:13 -07:00
}
2016-04-17 21:25:43 -07:00
id.IsMissingEpisode = IsMissingEpisode;
2014-02-06 20:10:13 -07:00
id.IndexNumberEnd = IndexNumberEnd;
2016-04-17 21:25:43 -07:00
id.IsVirtualUnaired = IsVirtualUnaired;
2014-02-06 20:10:13 -07:00
return id;
}
2014-02-10 11:39:41 -07:00
2014-02-12 22:11:54 -07:00
public override bool BeforeMetadataRefresh()
2014-02-10 11:39:41 -07:00
{
2014-02-12 22:11:54 -07:00
var hasChanges = base.BeforeMetadataRefresh();
2014-02-10 11:39:41 -07:00
2015-10-23 09:04:33 -07:00
try
2014-02-10 11:39:41 -07:00
{
2015-10-23 09:04:33 -07:00
if (LibraryManager.FillMissingEpisodeNumbersFromPath(this))
{
hasChanges = true;
}
}
catch (Exception ex)
{
Logger.ErrorException("Error in FillMissingEpisodeNumbersFromPath. Episode: {0}", ex, Path ?? Name ?? Id.ToString());
2014-02-10 11:39:41 -07:00
}
2016-05-01 22:32:04 -07:00
if (!ParentIndexNumber.HasValue)
{
var season = Season;
if (season != null)
{
if (season.ParentIndexNumber.HasValue)
{
ParentIndexNumber = season.ParentIndexNumber;
hasChanges = true;
}
}
}
2014-02-12 22:11:54 -07:00
return hasChanges;
2014-02-10 11:39:41 -07:00
}
2013-02-20 18:33:05 -07:00
}
}