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

328 lines
9.4 KiB
C#
Raw Normal View History

2014-02-10 18:39:41 +00:00
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
2014-02-07 03:10:13 +00:00
using MediaBrowser.Model.Configuration;
2014-02-10 18:39:41 +00:00
using MediaBrowser.Model.Entities;
using System;
2013-10-26 22:01:21 +00:00
using System.Collections.Generic;
2013-02-21 01:33:05 +00:00
using System.Linq;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities.TV
{
/// <summary>
/// Class Episode
/// </summary>
2014-02-08 20:02:35 +00:00
public class Episode : Video, IHasLookupInfo<EpisodeInfo>, IHasSeries
2013-02-21 01:33:05 +00:00
{
2013-11-15 21:31:33 +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; }
2013-11-15 21:31:33 +00:00
2013-12-08 18:07:45 +00: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 18:07:45 +00: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-07 03:10:13 +00:00
2013-02-21 01:33:05 +00:00
/// <summary>
/// We want to group into series not show individually in an index
/// </summary>
/// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public override bool GroupInIndex
{
get { return true; }
}
[IgnoreDataMember]
public int? AiredSeasonNumber
{
get
{
2013-11-23 20:01:09 +00:00
return AirsAfterSeasonNumber ?? AirsBeforeSeasonNumber ?? PhysicalSeasonNumber;
}
}
[IgnoreDataMember]
public int? PhysicalSeasonNumber
{
get
{
var value = ParentIndexNumber;
if (value.HasValue)
{
return value;
}
var season = Season;
return season != null ? season.IndexNumber : null;
}
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// We roll up into series
/// </summary>
/// <value>The index container.</value>
[IgnoreDataMember]
public override Folder IndexContainer
{
get
{
return FindParent<Season>();
2013-02-21 01:33:05 +00:00
}
}
/// <summary>
/// Gets the user data key.
2013-02-21 01:33:05 +00:00
/// </summary>
/// <returns>System.String.</returns>
public override string GetUserDataKey()
2013-02-21 01:33:05 +00:00
{
2014-02-06 15:58:49 +00:00
var series = Series;
if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
2013-02-21 01:33:05 +00:00
{
2014-02-06 15:58:49 +00:00
return series.GetUserDataKey() + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000");
2013-02-21 01:33:05 +00:00
}
return base.GetUserDataKey();
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Our rating comes from our series
/// </summary>
2013-08-03 13:24:23 +00:00
[IgnoreDataMember]
public override string OfficialRatingForComparison
{
2014-02-06 15:58:49 +00:00
get
{
var series = Series;
return series != null ? series.OfficialRatingForComparison : base.OfficialRatingForComparison;
}
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// This Episode's Series Instance
/// </summary>
/// <value>The series.</value>
[IgnoreDataMember]
public Series Series
{
get { return FindParent<Series>(); }
2013-02-21 01:33:05 +00:00
}
[IgnoreDataMember]
public Season Season
{
get { return FindParent<Season>(); }
}
2014-02-08 20:02:35 +00:00
[IgnoreDataMember]
public string SeriesName
{
get
{
var series = Series;
return series == null ? null : series.Name;
}
}
/// <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;
}
2013-10-26 22:01:21 +00:00
2013-11-12 15:36:08 +00:00
[IgnoreDataMember]
2013-10-26 22:01:21 +00:00
public bool IsMissingEpisode
{
get
{
2014-02-10 20:11:46 +00:00
return LocationType == LocationType.Virtual && PremiereDate.HasValue && PremiereDate.Value < DateTime.UtcNow;
2013-10-26 22:01:21 +00:00
}
}
2013-11-12 15:36:08 +00:00
[IgnoreDataMember]
2013-10-26 22:01:21 +00:00
public bool IsUnaired
{
2013-10-28 12:26:00 +00:00
get { return PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date; }
2013-10-26 22:40:53 +00:00
}
2013-11-12 15:36:08 +00:00
[IgnoreDataMember]
2013-10-26 22:40:53 +00:00
public bool IsVirtualUnaired
{
2014-02-10 20:11:46 +00:00
get { return LocationType == LocationType.Virtual && IsUnaired; }
2013-10-26 22:01:21 +00:00
}
[IgnoreDataMember]
public Guid? SeasonId
{
get
{
// First see if the parent is a Season
var season = Season;
if (season != null)
{
return season.Id;
}
var seasonNumber = ParentIndexNumber;
// Parent is a Series
if (seasonNumber.HasValue)
{
var series = Series;
if (series != null)
{
season = series.Children.OfType<Season>()
.FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == seasonNumber.Value);
if (season != null)
{
return season.Id;
}
}
}
return null;
}
}
public override IEnumerable<string> GetDeletePaths()
{
return new[] { Path };
}
2013-12-26 16:53:23 +00:00
protected override bool GetBlockUnratedValue(UserConfiguration config)
{
return config.BlockUnratedItems.Contains(UnratedItem.Series);
2013-12-26 16:53:23 +00:00
}
2014-02-07 03:10:13 +00:00
public EpisodeInfo GetLookupInfo()
{
var id = GetItemLookupInfo<EpisodeInfo>();
var series = Series;
if (series != null)
{
id.SeriesProviderIds = series.ProviderIds;
2014-02-28 04:49:02 +00:00
id.AnimeSeriesIndex = series.AnimeSeriesIndex;
2014-02-07 03:10:13 +00:00
}
id.IndexNumberEnd = IndexNumberEnd;
return id;
}
2014-02-10 18:39:41 +00:00
2014-02-13 05:11:54 +00:00
public override bool BeforeMetadataRefresh()
2014-02-10 18:39:41 +00:00
{
2014-02-13 05:11:54 +00:00
var hasChanges = base.BeforeMetadataRefresh();
2014-02-10 18:39:41 +00:00
var locationType = LocationType;
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
{
if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path))
{
2014-02-13 05:11:54 +00:00
IndexNumber = TVUtils.GetEpisodeNumberFromFile(Path, Parent is Season);
2014-02-10 18:39:41 +00:00
// If a change was made record it
if (IndexNumber.HasValue)
{
2014-02-13 05:11:54 +00:00
hasChanges = true;
2014-02-10 18:39:41 +00:00
}
}
if (!IndexNumberEnd.HasValue && !string.IsNullOrEmpty(Path))
{
2014-02-13 05:11:54 +00:00
IndexNumberEnd = TVUtils.GetEndingEpisodeNumberFromFile(Path);
2014-02-10 18:39:41 +00:00
// If a change was made record it
if (IndexNumberEnd.HasValue)
{
2014-02-13 05:11:54 +00:00
hasChanges = true;
2014-02-10 18:39:41 +00:00
}
}
}
if (!ParentIndexNumber.HasValue)
{
var season = Season;
if (season != null)
{
ParentIndexNumber = season.IndexNumber;
}
2014-02-13 05:11:54 +00:00
if (!ParentIndexNumber.HasValue && !string.IsNullOrEmpty(Path))
{
ParentIndexNumber = TVUtils.GetSeasonNumberFromPath(Path);
// If a change was made record it
if (ParentIndexNumber.HasValue)
{
hasChanges = true;
}
}
2014-02-10 18:39:41 +00:00
// If a change was made record it
if (ParentIndexNumber.HasValue)
{
2014-02-13 05:11:54 +00:00
hasChanges = true;
2014-02-10 18:39:41 +00:00
}
}
2014-02-13 05:11:54 +00:00
return hasChanges;
2014-02-10 18:39:41 +00:00
}
2013-02-21 01:33:05 +00:00
}
}