@ -96,19 +96,29 @@ namespace MediaBrowser.Controller.Entities.TV
}
}
[IgnoreDataMember]
public override string PresentationUniqueKey
public override string CreatePresentationUniqueKey ( )
{
get
var userdatakeys = GetUserDataKeys ( ) ;
if ( userdatakeys . Count > 1 )
{
var userdatakeys = GetUserDataKeys ( ) ;
return AddLibrariesToPresentationUniqueKey ( userdatakeys [ 0 ] ) ;
}
return base . CreatePresentationUniqueKey ( ) ;
}
if ( userdatakeys . Count > 1 )
{
return userdatakeys [ 0 ] ;
}
return base . PresentationUniqueKey ;
private string AddLibrariesToPresentationUniqueKey ( string key )
{
var folders = LibraryManager . GetCollectionFolders ( this )
. Select ( i = > i . Id . ToString ( "N" ) )
. ToArray ( ) ;
if ( folders . Length = = 0 )
{
return key ;
}
return key + "-" + string . Join ( "-" , folders ) ;
}
private static string GetUniqueSeriesKey ( BaseItem series )
@ -117,7 +127,7 @@ namespace MediaBrowser.Controller.Entities.TV
{
return series . Id . ToString ( "N" ) ;
}
return series . PresentationUniqueKey;
return series . Get PresentationUniqueKey( ) ;
}
public override int GetChildCount ( User user )
@ -197,7 +207,30 @@ namespace MediaBrowser.Controller.Entities.TV
{
var config = user . Configuration ;
return GetSeasons ( user , config . DisplayMissingEpisodes , config . DisplayUnairedEpisodes ) ;
var seriesKey = GetUniqueSeriesKey ( this ) ;
Logger . Debug ( "GetSeasons SeriesKey: {0}" , seriesKey ) ;
var query = new InternalItemsQuery ( user )
{
AncestorWithPresentationUniqueKey = seriesKey ,
IncludeItemTypes = new [ ] { typeof ( Season ) . Name } ,
SortBy = new [ ] { ItemSortBy . SortName }
} ;
if ( ! config . DisplayMissingEpisodes & & ! config . DisplayUnairedEpisodes )
{
query . IsVirtualItem = false ;
}
else if ( ! config . DisplayMissingEpisodes )
{
query . IsMissing = false ;
}
else if ( ! config . DisplayUnairedEpisodes )
{
query . IsVirtualUnaired = false ;
}
return LibraryManager . GetItemList ( query ) . Cast < Season > ( ) ;
}
protected override Task < QueryResult < BaseItem > > GetItemsInternal ( InternalItemsQuery query )
@ -227,55 +260,43 @@ namespace MediaBrowser.Controller.Entities.TV
Func < BaseItem , bool > filter = i = > UserViewBuilder . Filter ( i , user , query , UserDataManager , LibraryManager ) ;
var items = GetSeasons ( user ) . Where ( filter ) ;
var result = PostFilterAndSort ( items , query );
var result = PostFilterAndSort ( items , query , false , true );
return Task . FromResult ( result ) ;
}
public IEnumerable < Season> GetSeasons ( User user , bool includeMissingSeasons , bool includeVirtualUnaired )
public IEnumerable < Episode> GetEpisodes ( User user )
{
IEnumerable < Season > seasons ;
var seriesKey = GetUniqueSeriesKey ( this ) ;
Logger . Debug ( "GetEpisodes seriesKey: {0}" , seriesKey ) ;
seasons = LibraryManager . GetItemList ( new InternalItemsQuery ( user )
var query = new InternalItemsQuery ( user )
{
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey ( this ) ,
IncludeItemTypes = new [ ] { typeof ( Season ) . Name } ,
SortBy = new [ ] { ItemSortBy . SortName }
} ) . Cast < Season > ( ) ;
if ( ! includeMissingSeasons )
AncestorWithPresentationUniqueKey = seriesKey ,
IncludeItemTypes = new [ ] { typeof ( Episode ) . Name , typeof ( Season ) . Name } ,
SortBy = new [ ] { ItemSortBy . SortName }
} ;
var config = user . Configuration ;
if ( ! config . DisplayMissingEpisodes & & ! config . DisplayUnairedEpisodes )
{
seasons = seasons . Where ( i = > ! ( i . IsMissingSeason ) ) ;
query. IsVirtualItem = false ;
}
if ( ! includeVirtualUnaired )
else if ( ! config . DisplayMissingEpisodes )
{
seasons = seasons . Where ( i = > ! i . IsVirtualUnaired ) ;
query. IsMissing = false ;
}
return seasons ;
}
public IEnumerable < Episode > GetEpisodes ( User user )
{
var config = user . Configuration ;
return GetEpisodes ( user , config . DisplayMissingEpisodes , config . DisplayUnairedEpisodes ) ;
}
public IEnumerable < Episode > GetEpisodes ( User user , bool includeMissing , bool includeVirtualUnaired )
{
var allItems = LibraryManager . GetItemList ( new InternalItemsQuery ( user )
else if ( ! config . DisplayUnairedEpisodes )
{
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey ( this ) ,
IncludeItemTypes = new [ ] { typeof ( Episode ) . Name , typeof ( Season ) . Name } ,
SortBy = new [ ] { ItemSortBy . SortName }
query . IsVirtualUnaired = false ;
}
} ) . ToList ( ) ;
var allItems = LibraryManager . GetItemList ( query ) . ToList ( ) ;
Logger . Debug ( "GetEpisodes return {0} items from database" , allItems . Count ) ;
var allSeriesEpisodes = allItems . OfType < Episode > ( ) . ToList ( ) ;
var allEpisodes = allItems . OfType < Season > ( )
. SelectMany ( i = > i . GetEpisodes ( this , user , includeMissing, includeVirtualUnaired , allSeriesEpisodes) )
. SelectMany ( i = > i . GetEpisodes ( this , user , allSeriesEpisodes ) )
. Reverse ( )
. ToList ( ) ;
@ -352,78 +373,68 @@ namespace MediaBrowser.Controller.Entities.TV
progress . Report ( 100 ) ;
}
public IEnumerable < Episode > GetEpisodes ( User user , Season season )
{
var config = user . Configuration ;
return GetEpisodes ( user , season , config . DisplayMissingEpisodes , config . DisplayUnairedEpisodes ) ;
}
private IEnumerable < Episode > GetAllEpisodes ( User user )
{
return LibraryManager . GetItemList ( new InternalItemsQuery ( user )
Logger . Debug ( "Series.GetAllEpisodes entering GetItemList" ) ;
var result = LibraryManager . GetItemList ( new InternalItemsQuery ( user )
{
AncestorWithPresentationUniqueKey = GetUniqueSeriesKey ( this ) ,
IncludeItemTypes = new [ ] { typeof ( Episode ) . Name } ,
SortBy = new [ ] { ItemSortBy . SortName }
} ) . Cast < Episode > ( ) ;
}
} ) . Cast < Episode > ( ) . ToList ( ) ;
public IEnumerable < Episode > GetEpisodes ( User user , Season parentSeason , bool includeMissingEpisodes , bool includeVirtualUnairedEpisodes )
{
IEnumerable < Episode > episodes = GetAllEpisodes ( user ) ;
Logger . Debug ( "Series.GetAllEpisodes returning {0} episodes" , result . Count ) ;
return GetEpisodes( user , pa rentSea son, incl udeMissingEpisodes, inc ludeVir tualUnairedEpisodes, episodes ) ;
return result ;
}
public IEnumerable < Episode > Get Episodes( User user , Season parentSeason , bool includeMissingEpisodes , bool includeVirtualUnairedEpisodes , IEnumerable < Episode > allSeriesEpisodes )
public IEnumerable < Episode > Get Season Episodes( User user , Season parentSeason )
{
if ( allSeriesEpisodes = = null )
var seriesKey = GetUniqueSeriesKey ( this ) ;
Logger . Debug ( "GetSeasonEpisodes seriesKey: {0}" , seriesKey ) ;
var query = new InternalItemsQuery ( user )
{
return GetEpisodes ( user , parentSeason , includeMissingEpisodes , includeVirtualUnairedEpisodes ) ;
AncestorWithPresentationUniqueKey = seriesKey ,
IncludeItemTypes = new [ ] { typeof ( Episode ) . Name } ,
SortBy = new [ ] { ItemSortBy . SortName }
} ;
var config = user . Configuration ;
if ( ! config . DisplayMissingEpisodes & & ! config . DisplayUnairedEpisodes )
{
query . IsVirtualItem = false ;
}
var episodes = FilterEpisodesBySeason ( allSeriesEpisodes , parentSeason , ConfigurationManager . Configuration . DisplaySpecialsWithinSeasons ) ;
if ( ! includeMissingEpisodes )
else if ( ! config . DisplayMissingEpisodes )
{
episodes = episodes . Where ( i = > ! i . IsMissingEpisode ) ;
query . IsMissing = false ;
}
if ( ! includeVirtual UnairedEpisodes)
else if ( ! config . Display UnairedEpisodes)
{
episodes = episodes . Where ( i = > ! i . IsVirtualUnaired ) ;
query. IsVirtualUnaired = false ;
}
var sortBy = ( parentSeason . IndexNumber ? ? - 1 ) = = 0 ? ItemSortBy . SortName : ItemSortBy . AiredEpisodeOrder ;
var allItems = LibraryManager . GetItemList ( query ) . OfType < Episode > ( ) ;
return LibraryManager . Sort ( episodes , user , new [ ] { sortBy } , SortOrder . Ascending )
. Cast < Episode > ( ) ;
return GetSeasonEpisodes ( user , parentSeason , allItems ) ;
}
/// <summary>
/// Filters the episodes by season.
/// </summary>
public static IEnumerable < Episode > FilterEpisodesBySeason ( IEnumerable < Episode > episodes , int seasonNumber , bool includeSpecials )
public IEnumerable < Episode > GetSeasonEpisodes ( User user , Season parentSeason , IEnumerable < Episode > allSeriesEpisodes )
{
if ( ! includeSpecials | | seasonNumber < 1 )
if ( allSeriesEpisodes = = null )
{
return episodes . Where ( i = > ( i . ParentIndexNumber ? ? - 1 ) = = seasonNumber ) ;
Logger . Debug ( "GetSeasonEpisodes allSeriesEpisodes is null" ) ;
return GetSeasonEpisodes ( user , parentSeason ) ;
}
return episodes . Where ( i = >
{
var episode = i ;
if ( episode ! = null )
{
var currentSeasonNumber = episode . AiredSeasonNumber ;
Logger . Debug ( "GetSeasonEpisodes FilterEpisodesBySeason" ) ;
var episodes = FilterEpisodesBySeason ( allSeriesEpisodes , parentSeason , ConfigurationManager . Configuration . DisplaySpecialsWithinSeasons ) ;
return currentSeasonNumber . HasValue & & currentSeasonNumber . Value = = seasonNumber ;
}
var sortBy = ( parentSeason . IndexNumber ? ? - 1 ) = = 0 ? ItemSortBy . SortName : ItemSortBy . AiredEpisodeOrder ;
return false ;
} ) ;
return LibraryManager . Sort ( episodes , user , new [ ] { sortBy } , SortOrder . Ascending )
. Cast < Episode > ( ) ;
}
/// <summary>
@ -454,6 +465,32 @@ namespace MediaBrowser.Controller.Entities.TV
} ) ;
}
/// <summary>
/// Filters the episodes by season.
/// </summary>
public static IEnumerable < Episode > FilterEpisodesBySeason ( IEnumerable < Episode > episodes , int seasonNumber , bool includeSpecials )
{
if ( ! includeSpecials | | seasonNumber < 1 )
{
return episodes . Where ( i = > ( i . ParentIndexNumber ? ? - 1 ) = = seasonNumber ) ;
}
return episodes . Where ( i = >
{
var episode = i ;
if ( episode ! = null )
{
var currentSeasonNumber = episode . AiredSeasonNumber ;
return currentSeasonNumber . HasValue & & currentSeasonNumber . Value = = seasonNumber ;
}
return false ;
} ) ;
}
protected override bool GetBlockUnratedValue ( UserPolicy config )
{
return config . BlockUnratedItems . Contains ( UnratedItem . Series ) ;
@ -509,5 +546,15 @@ namespace MediaBrowser.Controller.Entities.TV
return list ;
}
[IgnoreDataMember]
public override bool StopRefreshIfLocalMetadataFound
{
get
{
// Need people id's from internet metadata
return false ;
}
}
}
}