2014-12-19 05:20:07 +01:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-02-07 04:10:13 +01:00
|
|
|
|
using MediaBrowser.Model.Configuration;
|
2014-02-10 19:39:41 +01:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-12-23 04:58:14 +01:00
|
|
|
|
using MediaBrowser.Model.Users;
|
2014-02-04 21:19:29 +01:00
|
|
|
|
using System;
|
2013-10-27 00:01:21 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities.TV
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Episode
|
|
|
|
|
/// </summary>
|
2014-02-08 21:02:35 +01:00
|
|
|
|
public class Episode : Video, IHasLookupInfo<EpisodeInfo>, IHasSeries
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-11-15 22:31:33 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the season in which it aired.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The aired season.</value>
|
2013-11-17 16:27:48 +01:00
|
|
|
|
public int? AirsBeforeSeasonNumber { get; set; }
|
|
|
|
|
public int? AirsAfterSeasonNumber { get; set; }
|
|
|
|
|
public int? AirsBeforeEpisodeNumber { get; set; }
|
2013-11-15 22:31:33 +01:00
|
|
|
|
|
2013-12-08 19:07:45 +01: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 23:16:59 +01:00
|
|
|
|
public float? DvdEpisodeNumber { get; set; }
|
2013-12-08 19:07:45 +01:00
|
|
|
|
|
2013-12-10 21:42:42 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the absolute episode number.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The absolute episode number.</value>
|
|
|
|
|
public int? AbsoluteEpisodeNumber { get; set; }
|
2014-02-04 21:19:29 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is the ending episode number for double episodes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The index number.</value>
|
|
|
|
|
public int? IndexNumberEnd { get; set; }
|
2014-02-07 04:10:13 +01:00
|
|
|
|
|
2015-01-28 22:29:02 +01:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
protected override bool SupportsOwnedItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return IsStacked || MediaSourceCount > 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-22 16:33:14 +01:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public int? AiredSeasonNumber
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-11-23 21:01:09 +01:00
|
|
|
|
return AirsAfterSeasonNumber ?? AirsBeforeSeasonNumber ?? PhysicalSeasonNumber;
|
2013-11-22 16:33:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public int? PhysicalSeasonNumber
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var value = ParentIndexNumber;
|
|
|
|
|
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 21:19:29 +01:00
|
|
|
|
var season = Season;
|
2013-11-22 16:33:14 +01:00
|
|
|
|
|
|
|
|
|
return season != null ? season.IndexNumber : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 06:06:30 +02:00
|
|
|
|
[IgnoreDataMember]
|
2014-07-05 07:21:13 +02:00
|
|
|
|
public override Folder LatestItemsIndexContainer
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Series;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 06:54:35 +02:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override BaseItem DisplayParent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Season ?? Parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
2013-04-13 20:02:30 +02:00
|
|
|
|
/// Gets the user data key.
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// </summary>
|
2013-04-13 20:02:30 +02:00
|
|
|
|
/// <returns>System.String.</returns>
|
2015-01-24 23:33:26 +01:00
|
|
|
|
protected override string CreateUserDataKey()
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-06 16:58:49 +01:00
|
|
|
|
var series = Series;
|
|
|
|
|
|
|
|
|
|
if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-06 16:58:49 +01:00
|
|
|
|
return series.GetUserDataKey() + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000");
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-04-13 20:02:30 +02:00
|
|
|
|
|
2015-01-24 23:33:26 +01:00
|
|
|
|
return base.CreateUserDataKey();
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 01:28:07 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Our rating comes from our series
|
|
|
|
|
/// </summary>
|
2013-08-03 15:24:23 +02:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override string OfficialRatingForComparison
|
2013-03-27 01:28:07 +01:00
|
|
|
|
{
|
2014-02-06 16:58:49 +01:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var series = Series;
|
|
|
|
|
return series != null ? series.OfficialRatingForComparison : base.OfficialRatingForComparison;
|
|
|
|
|
}
|
2013-03-27 01:28:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This Episode's Series Instance
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The series.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public Series Series
|
|
|
|
|
{
|
2014-02-04 21:19:29 +01:00
|
|
|
|
get { return FindParent<Series>(); }
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 21:19:29 +01:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public Season Season
|
|
|
|
|
{
|
2014-10-16 05:26:39 +02:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var season = FindParent<Season>();
|
|
|
|
|
|
|
|
|
|
// Episodes directly in series folder
|
|
|
|
|
if (season == null)
|
|
|
|
|
{
|
2014-10-24 06:54:35 +02:00
|
|
|
|
var series = Series;
|
2014-10-16 05:26:39 +02:00
|
|
|
|
|
2015-07-31 22:38:08 +02:00
|
|
|
|
if (series != null && ParentIndexNumber.HasValue)
|
2014-10-16 05:26:39 +02:00
|
|
|
|
{
|
|
|
|
|
var findNumber = ParentIndexNumber.Value;
|
|
|
|
|
|
|
|
|
|
season = series.Children
|
|
|
|
|
.OfType<Season>()
|
|
|
|
|
.FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == findNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return season;
|
|
|
|
|
}
|
2014-02-04 21:19:29 +01:00
|
|
|
|
}
|
2013-05-24 04:05:31 +02:00
|
|
|
|
|
2014-12-23 04:58:14 +01:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public bool IsInSeasonFolder
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return FindParent<Season>() != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 21:02:35 +01:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public string SeriesName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var series = Series;
|
|
|
|
|
return series == null ? null : series.Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 02:46:46 +01: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;
|
|
|
|
|
}
|
2013-10-16 00:16:26 +02: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-27 00:01:21 +02:00
|
|
|
|
|
2014-08-14 15:24:30 +02:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsRemoteImageDownloading
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (IsMissingEpisode)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 16:36:08 +01:00
|
|
|
|
[IgnoreDataMember]
|
2013-10-27 00:01:21 +02:00
|
|
|
|
public bool IsMissingEpisode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-03-04 05:53:48 +01:00
|
|
|
|
return LocationType == LocationType.Virtual && !IsUnaired;
|
2013-10-27 00:01:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 16:36:08 +01:00
|
|
|
|
[IgnoreDataMember]
|
2013-10-27 00:01:21 +02:00
|
|
|
|
public bool IsUnaired
|
|
|
|
|
{
|
2013-10-28 13:26:00 +01:00
|
|
|
|
get { return PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date; }
|
2013-10-27 00:40:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 16:36:08 +01:00
|
|
|
|
[IgnoreDataMember]
|
2013-10-27 00:40:53 +02:00
|
|
|
|
public bool IsVirtualUnaired
|
|
|
|
|
{
|
2014-02-10 21:11:46 +01:00
|
|
|
|
get { return LocationType == LocationType.Virtual && IsUnaired; }
|
2013-10-27 00:01:21 +02:00
|
|
|
|
}
|
2013-12-01 20:31:58 +01:00
|
|
|
|
|
2013-12-04 05:18:50 +01:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public Guid? SeasonId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// First see if the parent is a Season
|
2014-02-04 21:19:29 +01:00
|
|
|
|
var season = Season;
|
2013-12-04 05:18:50 +01:00
|
|
|
|
|
|
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
return season.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-01 20:31:58 +01:00
|
|
|
|
public override IEnumerable<string> GetDeletePaths()
|
|
|
|
|
{
|
|
|
|
|
return new[] { Path };
|
|
|
|
|
}
|
2013-12-26 17:53:23 +01:00
|
|
|
|
|
2014-12-20 07:06:27 +01:00
|
|
|
|
protected override bool GetBlockUnratedValue(UserPolicy config)
|
2013-12-26 17:53:23 +01:00
|
|
|
|
{
|
2014-02-21 16:24:29 +01:00
|
|
|
|
return config.BlockUnratedItems.Contains(UnratedItem.Series);
|
2013-12-26 17:53:23 +01:00
|
|
|
|
}
|
2014-02-07 04:10:13 +01:00
|
|
|
|
|
|
|
|
|
public EpisodeInfo GetLookupInfo()
|
|
|
|
|
{
|
|
|
|
|
var id = GetItemLookupInfo<EpisodeInfo>();
|
|
|
|
|
|
|
|
|
|
var series = Series;
|
|
|
|
|
|
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
id.SeriesProviderIds = series.ProviderIds;
|
2014-02-28 05:49:02 +01:00
|
|
|
|
id.AnimeSeriesIndex = series.AnimeSeriesIndex;
|
2014-02-07 04:10:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id.IndexNumberEnd = IndexNumberEnd;
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
2014-02-10 19:39:41 +01:00
|
|
|
|
|
2014-02-13 06:11:54 +01:00
|
|
|
|
public override bool BeforeMetadataRefresh()
|
2014-02-10 19:39:41 +01:00
|
|
|
|
{
|
2014-02-13 06:11:54 +01:00
|
|
|
|
var hasChanges = base.BeforeMetadataRefresh();
|
2014-02-10 19:39:41 +01:00
|
|
|
|
|
2014-12-19 05:20:07 +01:00
|
|
|
|
if (LibraryManager.FillMissingEpisodeNumbersFromPath(this))
|
2014-02-10 19:39:41 +01:00
|
|
|
|
{
|
2014-12-19 05:20:07 +01:00
|
|
|
|
hasChanges = true;
|
2014-02-10 19:39:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 06:11:54 +01:00
|
|
|
|
return hasChanges;
|
2014-02-10 19:39:41 +01:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|