using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities.TV
{
///
/// Class Episode
///
public class Episode : Video
{
///
/// Episodes have a special Metadata folder
///
/// The meta location.
[IgnoreDataMember]
public override string MetaLocation
{
get
{
return System.IO.Path.Combine(Parent.Path, "metadata");
}
}
[IgnoreDataMember]
protected override bool UseParentPathToCreateResolveArgs
{
get
{
return false;
}
}
///
/// Gets the season in which it aired.
///
/// The aired season.
public int? AirsBeforeSeasonNumber { get; set; }
public int? AirsAfterSeasonNumber { get; set; }
public int? AirsBeforeEpisodeNumber { get; set; }
///
/// We want to group into series not show individually in an index
///
/// true if [group in index]; otherwise, false.
[IgnoreDataMember]
public override bool GroupInIndex
{
get { return true; }
}
[IgnoreDataMember]
public int? AiredSeasonNumber
{
get
{
return AirsAfterSeasonNumber ?? AirsBeforeSeasonNumber ?? PhysicalSeasonNumber;
}
}
[IgnoreDataMember]
public int? PhysicalSeasonNumber
{
get
{
var value = ParentIndexNumber;
if (value.HasValue)
{
return value;
}
var season = Parent as Season;
return season != null ? season.IndexNumber : null;
}
}
///
/// We roll up into series
///
/// The index container.
[IgnoreDataMember]
public override Folder IndexContainer
{
get
{
return Season;
}
}
///
/// Gets the user data key.
///
/// System.String.
public override string GetUserDataKey()
{
if (Series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue)
{
return Series.GetUserDataKey() + ParentIndexNumber.Value.ToString("000") + IndexNumber.Value.ToString("000");
}
return base.GetUserDataKey();
}
///
/// Override this if you need to combine/collapse person information
///
/// All people.
[IgnoreDataMember]
public override IEnumerable AllPeople
{
get
{
if (People == null) return Series != null ? Series.People : People;
return Series != null && Series.People != null ? People.Concat(Series.People) : base.AllPeople;
}
}
///
/// Gets all genres.
///
/// All genres.
[IgnoreDataMember]
public override IEnumerable AllGenres
{
get
{
if (Genres == null) return Series != null ? Series.Genres : Genres;
return Series != null && Series.Genres != null ? Genres.Concat(Series.Genres) : base.AllGenres;
}
}
///
/// Gets all studios.
///
/// All studios.
[IgnoreDataMember]
public override IEnumerable AllStudios
{
get
{
if (Studios == null) return Series != null ? Series.Studios : Studios;
return Series != null && Series.Studios != null ? Studios.Concat(Series.Studios) : base.AllStudios;
}
}
///
/// Our rating comes from our series
///
[IgnoreDataMember]
public override string OfficialRatingForComparison
{
get { return Series != null ? Series.OfficialRatingForComparison : base.OfficialRatingForComparison; }
}
///
/// Our rating comes from our series
///
[IgnoreDataMember]
public override string CustomRatingForComparison
{
get { return Series != null ? Series.CustomRatingForComparison : base.CustomRatingForComparison; }
}
///
/// The _series
///
private Series _series;
///
/// This Episode's Series Instance
///
/// The series.
[IgnoreDataMember]
public Series Series
{
get { return _series ?? (_series = FindParent()); }
}
///
/// The _season
///
private Season _season;
///
/// This Episode's Season Instance
///
/// The season.
[IgnoreDataMember]
public Season Season
{
get { return _season ?? (_season = FindParent()); }
}
///
/// This is the ending episode number for double episodes.
///
/// The index number.
public int? IndexNumberEnd { get; set; }
///
/// Creates the name of the sort.
///
/// System.String.
protected override string CreateSortName()
{
return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("000-") : "")
+ (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
}
///
/// Determines whether [contains episode number] [the specified number].
///
/// The number.
/// true if [contains episode number] [the specified number]; otherwise, false.
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 bool IsMissingEpisode
{
get
{
return LocationType == Model.Entities.LocationType.Virtual && PremiereDate.HasValue && PremiereDate.Value < DateTime.UtcNow;
}
}
[IgnoreDataMember]
public bool IsUnaired
{
get { return PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date; }
}
[IgnoreDataMember]
public bool IsVirtualUnaired
{
get { return LocationType == Model.Entities.LocationType.Virtual && IsUnaired; }
}
}
}