2014-12-18 23:20:07 -05:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-02-06 22:10:13 -05:00
|
|
|
|
using MediaBrowser.Model.Configuration;
|
2014-02-10 13:39:41 -05:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using System;
|
2013-10-26 18:01:21 -04:00
|
|
|
|
using System.Collections.Generic;
|
2016-12-07 15:03:00 -05:00
|
|
|
|
using System.Globalization;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using System.Linq;
|
2017-02-18 03:32:17 -05:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-25 15:02:04 -04:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities.TV
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Class Episode
|
|
|
|
|
|
/// </summary>
|
2016-05-31 19:25:26 +01:00
|
|
|
|
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 16:11:30 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the season in which it aired.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The aired season.</value>
|
|
|
|
|
|
public int? AirsBeforeSeasonNumber { get; set; }
|
2013-11-17 10:27:48 -05:00
|
|
|
|
public int? AirsAfterSeasonNumber { get; set; }
|
|
|
|
|
|
public int? AirsBeforeEpisodeNumber { get; set; }
|
2013-11-15 16:31:33 -05:00
|
|
|
|
|
2013-12-08 13:07:45 -05: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>
|
2013-12-08 17:16:59 -05:00
|
|
|
|
public float? DvdEpisodeNumber { get; set; }
|
2013-12-08 13:07:45 -05:00
|
|
|
|
|
2013-12-10 15:42:42 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the absolute episode number.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The absolute episode number.</value>
|
|
|
|
|
|
public int? AbsoluteEpisodeNumber { get; set; }
|
2014-02-04 15:19:29 -05:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This is the ending episode number for double episodes.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The index number.</value>
|
2016-07-10 11:44:53 -04:00
|
|
|
|
public int? IndexNumberEnd { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public string SeriesSortName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public string FindSeriesSortName()
|
|
|
|
|
|
{
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
return series == null ? SeriesSortName : series.SortName;
|
|
|
|
|
|
}
|
2014-02-06 22:10:13 -05:00
|
|
|
|
|
2015-01-28 16:29:02 -05:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
protected override bool SupportsOwnedItems
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsStacked || MediaSourceCount > 1;
|
|
|
|
|
|
}
|
2016-11-21 03:54:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public override bool SupportsInheritedParentImages
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return true; }
|
2015-01-28 16:29:02 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-22 10:33:14 -05:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public int? AiredSeasonNumber
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2016-05-02 01:32:04 -04:00
|
|
|
|
return AirsAfterSeasonNumber ?? AirsBeforeSeasonNumber ?? ParentIndexNumber;
|
2013-11-22 10:33:14 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-29 00:06:30 -04:00
|
|
|
|
[IgnoreDataMember]
|
2014-07-05 01:21:13 -04:00
|
|
|
|
public override Folder LatestItemsIndexContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Series;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-24 00:54:35 -04:00
|
|
|
|
[IgnoreDataMember]
|
2016-04-09 00:16:53 -04:00
|
|
|
|
public override Guid? DisplayParentId
|
2014-10-24 00:54:35 -04:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2016-04-09 00:16:53 -04:00
|
|
|
|
return SeasonId;
|
2014-10-24 00:54:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-30 19:05:21 -04:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
protected override bool EnableDefaultVideoUserDataKeys
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2016-04-30 19:05:21 -04:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-02-10 15:06:52 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override double? GetDefaultPrimaryImageAspectRatio()
|
|
|
|
|
|
{
|
|
|
|
|
|
double value = 16;
|
|
|
|
|
|
value /= 9;
|
|
|
|
|
|
|
|
|
|
|
|
return value;
|
2016-04-30 19:05:21 -04:00
|
|
|
|
}
|
2014-02-06 10:58:49 -05:00
|
|
|
|
|
2016-04-30 19:05:21 -04:00
|
|
|
|
public override List<string> GetUserDataKeys()
|
|
|
|
|
|
{
|
|
|
|
|
|
var list = base.GetUserDataKeys();
|
|
|
|
|
|
|
|
|
|
|
|
var series = Series;
|
2014-02-06 10:58:49 -05:00
|
|
|
|
if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2016-06-03 20:15:14 -04: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 20:33:05 -05:00
|
|
|
|
}
|
2013-04-13 14:02:30 -04:00
|
|
|
|
|
2016-04-30 19:05:21 -04:00
|
|
|
|
return list;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This Episode's Series Instance
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The series.</value>
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public Series Series
|
|
|
|
|
|
{
|
2016-08-25 02:44:24 -04:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2016-08-25 13:48:16 -04:00
|
|
|
|
var seriesId = SeriesId ?? FindSeriesId();
|
|
|
|
|
|
return seriesId.HasValue ? (LibraryManager.GetItemById(seriesId.Value) as Series) : null;
|
2016-08-25 02:44:24 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-02-04 15:19:29 -05:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public Season Season
|
|
|
|
|
|
{
|
2014-10-15 23:26:39 -04:00
|
|
|
|
get
|
|
|
|
|
|
{
|
2016-08-25 13:48:16 -04:00
|
|
|
|
var seasonId = SeasonId ?? FindSeasonId();
|
|
|
|
|
|
return seasonId.HasValue ? (LibraryManager.GetItemById(seasonId.Value) as Season) : null;
|
2014-10-15 23:26:39 -04:00
|
|
|
|
}
|
2014-02-04 15:19:29 -05:00
|
|
|
|
}
|
2013-05-23 22:05:31 -04:00
|
|
|
|
|
2014-12-22 22:58:14 -05:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public bool IsInSeasonFolder
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return FindParent<Season>() != null;
|
|
|
|
|
|
}
|
2016-12-06 03:24:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public string SeriesPresentationUniqueKey { get; set; }
|
2014-12-22 22:58:14 -05:00
|
|
|
|
|
2014-02-08 15:02:35 -05:00
|
|
|
|
[IgnoreDataMember]
|
2016-07-04 16:11:30 -04:00
|
|
|
|
public string SeriesName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
2016-12-06 03:24:29 -05:00
|
|
|
|
public string SeasonName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public string FindSeriesPresentationUniqueKey()
|
|
|
|
|
|
{
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
return series == null ? null : series.PresentationUniqueKey;
|
|
|
|
|
|
}
|
2016-07-04 16:11:30 -04:00
|
|
|
|
|
|
|
|
|
|
public string FindSeasonName()
|
|
|
|
|
|
{
|
2016-12-07 15:03:00 -05:00
|
|
|
|
var season = Season;
|
|
|
|
|
|
|
|
|
|
|
|
if (season == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ParentIndexNumber.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Season " + ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
|
}
|
2016-12-12 00:49:19 -05:00
|
|
|
|
return "Season Unknown";
|
2016-12-07 15:03:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-12 00:49:19 -05:00
|
|
|
|
return season.Name;
|
2016-07-04 16:11:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string FindSeriesName()
|
|
|
|
|
|
{
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
return series == null ? SeriesName : series.Name;
|
2016-07-05 01:40:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Guid? FindSeasonId()
|
|
|
|
|
|
{
|
2016-08-25 02:44:24 -04: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 01:40:18 -04:00
|
|
|
|
return season == null ? (Guid?)null : season.Id;
|
2014-02-08 15:02:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-11 21:46:46 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates the name of the sort.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
|
protected override string CreateSortName()
|
|
|
|
|
|
{
|
2016-03-31 17:14:03 -04:00
|
|
|
|
return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("000 - ") : "")
|
2013-03-11 21:46:46 -04:00
|
|
|
|
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
|
|
|
|
|
|
}
|
2013-10-15 18:16:26 -04:00
|
|
|
|
|
|
|
|
|
|
/// <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 18:01:21 -04:00
|
|
|
|
|
2014-08-14 09:24:30 -04:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
|
public override bool SupportsRemoteImageDownloading
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsMissingEpisode)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-12 10:36:08 -05:00
|
|
|
|
[IgnoreDataMember]
|
2013-10-26 18:01:21 -04:00
|
|
|
|
public bool IsMissingEpisode
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2014-03-03 23:53:48 -05:00
|
|
|
|
return LocationType == LocationType.Virtual && !IsUnaired;
|
2013-10-26 18:01:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-12 10:36:08 -05:00
|
|
|
|
[IgnoreDataMember]
|
2013-10-26 18:40:53 -04:00
|
|
|
|
public bool IsVirtualUnaired
|
|
|
|
|
|
{
|
2014-02-10 15:11:46 -05:00
|
|
|
|
get { return LocationType == LocationType.Virtual && IsUnaired; }
|
2013-10-26 18:01:21 -04:00
|
|
|
|
}
|
2013-12-01 14:31:58 -05:00
|
|
|
|
|
2013-12-03 23:18:50 -05:00
|
|
|
|
[IgnoreDataMember]
|
2016-07-05 02:01:31 -04:00
|
|
|
|
public Guid? SeasonId { get; set; }
|
2016-07-07 23:22:02 -04:00
|
|
|
|
[IgnoreDataMember]
|
2016-07-05 02:01:31 -04:00
|
|
|
|
public Guid? SeriesId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public Guid? FindSeriesId()
|
|
|
|
|
|
{
|
2016-08-25 02:44:24 -04:00
|
|
|
|
var series = FindParent<Series>();
|
2016-07-05 02:01:31 -04:00
|
|
|
|
return series == null ? (Guid?)null : series.Id;
|
|
|
|
|
|
}
|
2013-12-03 23:18:50 -05:00
|
|
|
|
|
2015-10-29 09:28:05 -04: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 03:32:17 -05:00
|
|
|
|
public override IEnumerable<FileSystemMetadata> GetDeletePaths()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new[] {
|
|
|
|
|
|
new FileSystemMetadata
|
|
|
|
|
|
{
|
|
|
|
|
|
FullName = Path,
|
|
|
|
|
|
IsDirectory = IsFolder
|
|
|
|
|
|
}
|
|
|
|
|
|
}.Concat(GetLocalMetadataFilesToDelete());
|
|
|
|
|
|
}
|
2013-12-26 11:53:23 -05:00
|
|
|
|
|
2015-11-06 10:02:22 -05:00
|
|
|
|
public override UnratedItem GetBlockUnratedType()
|
2013-12-26 11:53:23 -05:00
|
|
|
|
{
|
2015-11-06 10:02:22 -05:00
|
|
|
|
return UnratedItem.Series;
|
2013-12-26 11:53:23 -05:00
|
|
|
|
}
|
2014-02-06 22:10:13 -05:00
|
|
|
|
|
|
|
|
|
|
public EpisodeInfo GetLookupInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
var id = GetItemLookupInfo<EpisodeInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
|
|
|
|
|
|
if (series != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
id.SeriesProviderIds = series.ProviderIds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-18 00:25:43 -04:00
|
|
|
|
id.IsMissingEpisode = IsMissingEpisode;
|
2014-02-06 22:10:13 -05:00
|
|
|
|
id.IndexNumberEnd = IndexNumberEnd;
|
2016-04-18 00:25:43 -04:00
|
|
|
|
id.IsVirtualUnaired = IsVirtualUnaired;
|
2014-02-06 22:10:13 -05:00
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
|
}
|
2014-02-10 13:39:41 -05:00
|
|
|
|
|
2014-02-13 00:11:54 -05:00
|
|
|
|
public override bool BeforeMetadataRefresh()
|
2014-02-10 13:39:41 -05:00
|
|
|
|
{
|
2014-02-13 00:11:54 -05:00
|
|
|
|
var hasChanges = base.BeforeMetadataRefresh();
|
2014-02-10 13:39:41 -05:00
|
|
|
|
|
2015-10-23 12:04:33 -04:00
|
|
|
|
try
|
2014-02-10 13:39:41 -05:00
|
|
|
|
{
|
2015-10-23 12:04:33 -04: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 13:39:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-02 01:32:04 -04:00
|
|
|
|
if (!ParentIndexNumber.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var season = Season;
|
|
|
|
|
|
if (season != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (season.ParentIndexNumber.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
ParentIndexNumber = season.ParentIndexNumber;
|
|
|
|
|
|
hasChanges = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-02-13 00:11:54 -05:00
|
|
|
|
return hasChanges;
|
2014-02-10 13:39:41 -05:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|