2017-06-03 07:36:32 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities.TV
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Episode
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Episode : Video, IHasTrailers, IHasLookupInfo<EpisodeInfo>, IHasSeries
|
2016-05-31 18:25:26 +00:00
|
|
|
|
{
|
|
|
|
|
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; }
|
|
|
|
|
|
2017-06-03 07:36:32 +00: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; }
|
|
|
|
|
|
|
|
|
|
/// <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; }
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2016-07-10 15:44:53 +00:00
|
|
|
|
public int? IndexNumberEnd { get; set; }
|
|
|
|
|
|
|
|
|
|
public string FindSeriesSortName()
|
|
|
|
|
{
|
|
|
|
|
var series = Series;
|
2017-05-05 17:55:38 +00:00
|
|
|
|
return series == null ? SeriesName : series.SortName;
|
2016-07-10 15:44:53 +00:00
|
|
|
|
}
|
2017-06-03 07:36:32 +00:00
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
protected override bool SupportsOwnedItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return IsStacked || MediaSourceCount > 1;
|
|
|
|
|
}
|
2016-11-21 08:54:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsInheritedParentImages
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
2017-06-03 07:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public int? AiredSeasonNumber
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return AirsAfterSeasonNumber ?? AirsBeforeSeasonNumber ?? ParentIndexNumber;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override Folder LatestItemsIndexContainer
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Series;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override Guid? DisplayParentId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return SeasonId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
protected override bool EnableDefaultVideoUserDataKeys
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-02-10 20:06:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override double? GetDefaultPrimaryImageAspectRatio()
|
|
|
|
|
{
|
|
|
|
|
double value = 16;
|
|
|
|
|
value /= 9;
|
|
|
|
|
|
|
|
|
|
return value;
|
2017-06-03 07:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<string> GetUserDataKeys()
|
|
|
|
|
{
|
|
|
|
|
var list = base.GetUserDataKeys();
|
|
|
|
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
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")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This Episode's Series Instance
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The series.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public Series Series
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-08-25 17:48:16 +00:00
|
|
|
|
var seriesId = SeriesId ?? FindSeriesId();
|
2017-06-03 07:36:32 +00:00
|
|
|
|
return seriesId.HasValue ? (LibraryManager.GetItemById(seriesId.Value) as Series) : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public Season Season
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-08-25 17:48:16 +00:00
|
|
|
|
var seasonId = SeasonId ?? FindSeasonId();
|
2017-06-03 07:36:32 +00:00
|
|
|
|
return seasonId.HasValue ? (LibraryManager.GetItemById(seasonId.Value) as Season) : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public bool IsInSeasonFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return FindParent<Season>() != null;
|
|
|
|
|
}
|
2016-12-06 08:24:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public string SeriesPresentationUniqueKey { get; set; }
|
2017-06-03 07:36:32 +00:00
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
2016-07-04 20:11:30 +00:00
|
|
|
|
public string SeriesName { get; set; }
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
2016-12-06 08:24:29 +00:00
|
|
|
|
public string SeasonName { get; set; }
|
|
|
|
|
|
|
|
|
|
public string FindSeriesPresentationUniqueKey()
|
|
|
|
|
{
|
|
|
|
|
var series = Series;
|
|
|
|
|
return series == null ? null : series.PresentationUniqueKey;
|
2017-06-03 07:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string FindSeasonName()
|
2016-07-04 20:11:30 +00:00
|
|
|
|
{
|
2017-06-03 07:36:32 +00:00
|
|
|
|
var season = Season;
|
|
|
|
|
|
|
|
|
|
if (season == null)
|
|
|
|
|
{
|
|
|
|
|
if (ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return "Season " + ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture);
|
2016-12-07 20:03:00 +00:00
|
|
|
|
}
|
2016-12-12 05:49:19 +00:00
|
|
|
|
return "Season Unknown";
|
2016-12-07 20:03:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 05:49:19 +00:00
|
|
|
|
return season.Name;
|
2016-07-04 20:11:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string FindSeriesName()
|
|
|
|
|
{
|
|
|
|
|
var series = Series;
|
|
|
|
|
return series == null ? SeriesName : series.Name;
|
2016-07-05 05:40:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid? FindSeasonId()
|
|
|
|
|
{
|
2016-08-25 06:44:24 +00:00
|
|
|
|
var season = FindParent<Season>();
|
|
|
|
|
|
|
|
|
|
// Episodes directly in series folder
|
|
|
|
|
if (season == null)
|
|
|
|
|
{
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
|
|
|
|
if (series != null && ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var findNumber = ParentIndexNumber.Value;
|
|
|
|
|
|
|
|
|
|
season = series.Children
|
|
|
|
|
.OfType<Season>()
|
|
|
|
|
.FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == findNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
return season == null ? (Guid?)null : season.Id;
|
2017-06-03 07:36:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates the name of the sort.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected override string CreateSortName()
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsRemoteImageDownloading
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (IsMissingEpisode)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public bool IsMissingEpisode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return LocationType == LocationType.Virtual && !IsUnaired;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public bool IsVirtualUnaired
|
|
|
|
|
{
|
|
|
|
|
get { return LocationType == LocationType.Virtual && IsUnaired; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
2016-07-05 06:01:31 +00:00
|
|
|
|
public Guid? SeasonId { get; set; }
|
2016-07-08 03:22:02 +00:00
|
|
|
|
[IgnoreDataMember]
|
2016-07-05 06:01:31 +00:00
|
|
|
|
public Guid? SeriesId { get; set; }
|
|
|
|
|
|
|
|
|
|
public Guid? FindSeriesId()
|
|
|
|
|
{
|
2017-06-03 07:36:32 +00:00
|
|
|
|
var series = FindParent<Series>();
|
2016-07-05 06:01:31 +00:00
|
|
|
|
return series == null ? (Guid?)null : series.Id;
|
2017-06-03 07:36:32 +00: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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 08:32:17 +00:00
|
|
|
|
public override IEnumerable<FileSystemMetadata> GetDeletePaths()
|
|
|
|
|
{
|
|
|
|
|
return new[] {
|
|
|
|
|
new FileSystemMetadata
|
|
|
|
|
{
|
|
|
|
|
FullName = Path,
|
|
|
|
|
IsDirectory = IsFolder
|
|
|
|
|
}
|
|
|
|
|
}.Concat(GetLocalMetadataFilesToDelete());
|
|
|
|
|
}
|
2017-06-03 07:36:32 +00:00
|
|
|
|
|
|
|
|
|
public override UnratedItem GetBlockUnratedType()
|
|
|
|
|
{
|
|
|
|
|
return UnratedItem.Series;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EpisodeInfo GetLookupInfo()
|
|
|
|
|
{
|
|
|
|
|
var id = GetItemLookupInfo<EpisodeInfo>();
|
|
|
|
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
id.SeriesProviderIds = series.ProviderIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id.IsMissingEpisode = IsMissingEpisode;
|
|
|
|
|
id.IndexNumberEnd = IndexNumberEnd;
|
|
|
|
|
id.IsVirtualUnaired = IsVirtualUnaired;
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool BeforeMetadataRefresh()
|
|
|
|
|
{
|
|
|
|
|
var hasChanges = base.BeforeMetadataRefresh();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (LibraryManager.FillMissingEpisodeNumbersFromPath(this))
|
|
|
|
|
{
|
|
|
|
|
hasChanges = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error in FillMissingEpisodeNumbersFromPath. Episode: {0}", ex, Path ?? Name ?? Id.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var season = Season;
|
|
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
if (season.ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ParentIndexNumber = season.ParentIndexNumber;
|
|
|
|
|
hasChanges = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hasChanges;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|