using System.Linq;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
namespace MediaBrowser.Controller.Entities.TV
{
///
/// Class Season
///
public class Season : Folder
{
///
/// Seasons are just containers
///
/// true if [include in index]; otherwise, false.
[IgnoreDataMember]
public override bool IncludeInIndex
{
get
{
return false;
}
}
///
/// We want to group into our Series
///
/// true if [group in index]; otherwise, false.
[IgnoreDataMember]
public override bool GroupInIndex
{
get
{
return true;
}
}
///
/// Override this to return the folder that should be used to construct a container
/// for this item in an index. GroupInIndex should be true as well.
///
/// The index container.
[IgnoreDataMember]
public override Folder IndexContainer
{
get
{
return Series;
}
}
// Genre, Rating and Stuido will all be the same
protected override Dictionary>> GetIndexByOptions()
{
return new Dictionary>> {
{LocalizedStrings.Instance.GetString("NoneDispPref"), null},
{LocalizedStrings.Instance.GetString("PerformerDispPref"), GetIndexByPerformer},
{LocalizedStrings.Instance.GetString("DirectorDispPref"), GetIndexByDirector},
{LocalizedStrings.Instance.GetString("YearDispPref"), GetIndexByYear},
};
}
///
/// Gets the user data key.
///
/// System.String.
public override string GetUserDataKey()
{
if (Series != null)
{
var seasonNo = IndexNumber ?? 0;
return Series.GetUserDataKey() + seasonNo.ToString("000");
}
return base.GetUserDataKey();
}
///
/// The _series
///
private Series _series;
///
/// This Episode's Series Instance
///
/// The series.
[IgnoreDataMember]
public Series Series
{
get { return _series ?? (_series = FindParent()); }
}
///
/// 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; }
}
///
/// Add files from the metadata folder to ResolveArgs
///
/// The args.
public static void AddMetadataFiles(ItemResolveArgs args)
{
var folder = args.GetFileSystemEntryByName("metadata");
if (folder != null)
{
args.AddMetadataFiles(new DirectoryInfo(folder.FullName).EnumerateFiles());
}
}
///
/// Creates ResolveArgs on demand
///
/// The path info.
/// ItemResolveArgs.
protected internal override ItemResolveArgs CreateResolveArgs(FileSystemInfo pathInfo = null)
{
var args = base.CreateResolveArgs(pathInfo);
AddMetadataFiles(args);
return args;
}
///
/// Creates the name of the sort.
///
/// System.String.
protected override string CreateSortName()
{
return IndexNumber != null ? IndexNumber.Value.ToString("0000") : Name;
}
public bool IsMissingSeason
{
get { return LocationType == Model.Entities.LocationType.Virtual && Children.OfType().All(i => i.IsMissingEpisode); }
}
public bool IsUnaired
{
get { return Children.OfType().All(i => i.IsUnaired); }
}
public bool IsVirtualUnaired
{
get { return LocationType == Model.Entities.LocationType.Virtual && IsUnaired; }
}
public bool IsMissingOrVirtualUnaired
{
get { return LocationType == Model.Entities.LocationType.Virtual && Children.OfType().All(i => i.IsVirtualUnaired || i.IsMissingEpisode); }
}
}
}