@ -663,19 +663,12 @@ namespace MediaBrowser.Server.Implementations.Dto
dto . GameSystem = item . GameSystemName ;
}
private List < string > Get Backdrop ImageTags( BaseItem item , int limit )
private List < string > Get ImageTags( BaseItem item , List < ItemImageInfo > images )
{
return GetCacheTags ( item , ImageType . Backdrop , limit ) . ToList ( ) ;
}
private List < string > GetScreenshotImageTags ( BaseItem item , int limit )
{
var hasScreenshots = item as IHasScreenshots ;
if ( hasScreenshots = = null )
{
return new List < string > ( ) ;
}
return GetCacheTags ( item , ImageType . Screenshot , limit ) . ToList ( ) ;
return images
. Select ( p = > GetImageCacheTag ( item , p ) )
. Where ( i = > i ! = null )
. ToList ( ) ;
}
private IEnumerable < string > GetCacheTags ( BaseItem item , ImageType type , int limit )
@ -850,53 +843,6 @@ namespace MediaBrowser.Server.Implementations.Dto
}
}
/// <summary>
/// If an item does not any backdrops, this can be used to find the first parent that does have one
/// </summary>
/// <param name="item">The item.</param>
/// <param name="owner">The owner.</param>
/// <returns>BaseItem.</returns>
private BaseItem GetParentBackdropItem ( BaseItem item , BaseItem owner )
{
var parent = item . GetParent ( ) ? ? owner ;
while ( parent ! = null )
{
if ( parent . GetImages ( ImageType . Backdrop ) . Any ( ) )
{
return parent ;
}
parent = parent . GetParent ( ) ;
}
return null ;
}
/// <summary>
/// If an item does not have a logo, this can be used to find the first parent that does have one
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="owner">The owner.</param>
/// <returns>BaseItem.</returns>
private BaseItem GetParentImageItem ( BaseItem item , ImageType type , BaseItem owner )
{
var parent = item . GetParent ( ) ? ? owner ;
while ( parent ! = null )
{
if ( parent . HasImage ( type ) )
{
return parent ;
}
parent = parent . GetParent ( ) ;
}
return null ;
}
/// <summary>
/// Gets the chapter info dto.
/// </summary>
@ -917,7 +863,7 @@ namespace MediaBrowser.Server.Implementations.Dto
{
Path = chapterInfo . ImagePath ,
Type = ImageType . Chapter ,
DateModified = _fileSystem. GetLastWriteTimeUtc ( chapterInfo . ImagePath )
DateModified = chapterInfo. ImageDateModified
} ) ;
}
@ -1027,7 +973,7 @@ namespace MediaBrowser.Server.Implementations.Dto
var backdropLimit = options . GetImageLimit ( ImageType . Backdrop ) ;
if ( backdropLimit > 0 )
{
dto . BackdropImageTags = Get Backdrop ImageTags( item , backdropLimit) ;
dto . BackdropImageTags = Get ImageTags( item , item. GetImages ( ImageType . Backdrop ) . Take ( backdropLimit) . ToList ( ) ) ;
}
if ( fields . Contains ( ItemFields . ScreenshotImageTags ) )
@ -1035,7 +981,7 @@ namespace MediaBrowser.Server.Implementations.Dto
var screenshotLimit = options . GetImageLimit ( ImageType . Screenshot ) ;
if ( screenshotLimit > 0 )
{
dto . ScreenshotImageTags = Get Screenshot ImageTags( item , screenshotLimit) ;
dto . ScreenshotImageTags = Get ImageTags( item , item. GetImages ( ImageType . Screenshot ) . Take ( screenshotLimit) . ToList ( ) ) ;
}
}
@ -1064,6 +1010,7 @@ namespace MediaBrowser.Server.Implementations.Dto
dto . Id = GetDtoId ( item ) ;
dto . IndexNumber = item . IndexNumber ;
dto . ParentIndexNumber = item . ParentIndexNumber ;
dto . IsFolder = item . IsFolder ;
dto . MediaType = item . MediaType ;
dto . LocationType = item . LocationType ;
@ -1076,15 +1023,11 @@ namespace MediaBrowser.Server.Implementations.Dto
dto . PreferredMetadataCountryCode = item . PreferredMetadataCountryCode ;
dto . PreferredMetadataLanguage = item . PreferredMetadataLanguage ;
var hasCriticRating = item as IHasCriticRating ;
if ( hasCriticRating ! = null )
{
dto . CriticRating = hasCriticRating . CriticRating ;
dto . CriticRating = item . CriticRating ;
if ( fields . Contains ( ItemFields . CriticRatingSummary ) )
{
dto . CriticRatingSummary = hasCriticRating . CriticRatingSummary ;
}
if ( fields . Contains ( ItemFields . CriticRatingSummary ) )
{
dto . CriticRatingSummary = item . CriticRatingSummary ;
}
var hasTrailers = item as IHasTrailers ;
@ -1127,23 +1070,7 @@ namespace MediaBrowser.Server.Implementations.Dto
if ( fields . Contains ( ItemFields . ShortOverview ) )
{
var hasShortOverview = item as IHasShortOverview ;
if ( hasShortOverview ! = null )
{
dto . ShortOverview = hasShortOverview . ShortOverview ;
}
}
// If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance
if ( backdropLimit > 0 & & dto . BackdropImageTags . Count = = 0 )
{
var parentWithBackdrop = GetParentBackdropItem ( item , owner ) ;
if ( parentWithBackdrop ! = null )
{
dto . ParentBackdropItemId = GetDtoId ( parentWithBackdrop ) ;
dto . ParentBackdropImageTags = GetBackdropImageTags ( parentWithBackdrop , backdropLimit ) ;
}
dto . ShortOverview = item . ShortOverview ;
}
if ( fields . Contains ( ItemFields . ParentId ) )
@ -1155,46 +1082,7 @@ namespace MediaBrowser.Server.Implementations.Dto
}
}
dto . ParentIndexNumber = item . ParentIndexNumber ;
// If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance
if ( ! dto . HasLogo & & options . GetImageLimit ( ImageType . Logo ) > 0 )
{
var parentWithLogo = GetParentImageItem ( item , ImageType . Logo , owner ) ;
if ( parentWithLogo ! = null )
{
dto . ParentLogoItemId = GetDtoId ( parentWithLogo ) ;
dto . ParentLogoImageTag = GetImageCacheTag ( parentWithLogo , ImageType . Logo ) ;
}
}
// If there is no art, indicate what parent has one in case the Ui wants to allow inheritance
if ( ! dto . HasArtImage & & options . GetImageLimit ( ImageType . Art ) > 0 )
{
var parentWithImage = GetParentImageItem ( item , ImageType . Art , owner ) ;
if ( parentWithImage ! = null )
{
dto . ParentArtItemId = GetDtoId ( parentWithImage ) ;
dto . ParentArtImageTag = GetImageCacheTag ( parentWithImage , ImageType . Art ) ;
}
}
// If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance
if ( ! dto . HasThumb & & options . GetImageLimit ( ImageType . Thumb ) > 0 )
{
var parentWithImage = GetParentImageItem ( item , ImageType . Thumb , owner ) ;
if ( parentWithImage ! = null )
{
dto . ParentThumbItemId = GetDtoId ( parentWithImage ) ;
dto . ParentThumbImageTag = GetImageCacheTag ( parentWithImage , ImageType . Thumb ) ;
}
}
AddInheritedImages ( dto , item , options , owner ) ;
if ( fields . Contains ( ItemFields . Path ) )
{
@ -1426,42 +1314,38 @@ namespace MediaBrowser.Server.Implementations.Dto
dto . SeasonId = seasonId . Value . ToString ( "N" ) ;
}
var episodeSeason = episode . Season ;
if ( episodeSeason ! = null )
dto . SeasonName = episode . SeasonName ;
var seriesId = episode . SeriesId ;
if ( seriesId . HasValue )
{
if ( fields . Contains ( ItemFields . SeasonName ) )
{
dto . SeasonName = episodeSeason . Name ;
}
dto . SeriesId = seriesId . Value . ToString ( "N" ) ;
}
var episodeSeries = episode . Series ;
Series episodeSeries = null ;
if ( episodeSeries ! = null )
if ( fields. Contains ( ItemFields . SeriesGenres ) )
{
if ( fields . Contains ( ItemFields . SeriesGenres ) )
episodeSeries = episodeSeries ? ? episode . Series ;
if ( episodeSeries ! = null )
{
dto . SeriesGenres = episodeSeries . Genres . ToList ( ) ;
}
}
dto . SeriesId = GetDtoId ( episodeSeries ) ;
if ( fields . Contains ( ItemFields . AirTime ) )
{
dto . AirTime = episodeSeries . AirTime ;
}
if ( options . GetImageLimit ( ImageType . Thumb ) > 0 )
{
dto . SeriesThumbImageTag = GetImageCacheTag ( episodeSeries , ImageType . Thumb ) ;
}
if ( options . GetImageLimit ( ImageType . Primary ) > 0 )
if ( fields . Contains ( ItemFields . SeriesPrimaryImage ) )
{
episodeSeries = episodeSeries ? ? episode . Series ;
if ( episodeSeries ! = null )
{
dto . SeriesPrimaryImageTag = GetImageCacheTag ( episodeSeries , ImageType . Primary ) ;
}
}
if ( fields . Contains ( ItemFields . SeriesStudio ) )
if ( fields . Contains ( ItemFields . SeriesStudio ) )
{
episodeSeries = episodeSeries ? ? episode . Series ;
if ( episodeSeries ! = null )
{
dto . SeriesStudio = episodeSeries . Studios . FirstOrDefault ( ) ;
}
@ -1483,16 +1367,29 @@ namespace MediaBrowser.Server.Implementations.Dto
var season = item as Season ;
if ( season ! = null )
{
series = season . Series ;
dto . SeriesName = season . SeriesName ;
var seriesId = season . SeriesId ;
if ( seriesId . HasValue )
{
dto . SeriesId = seriesId . Value . ToString ( "N" ) ;
}
if ( series ! = null )
series = null ;
if ( fields . Contains ( ItemFields . SeriesStudio ) )
{
dto . SeriesId = GetDtoId ( series ) ;
dto . SeriesName = series . Name ;
dto . AirTime = series . AirTime ;
dto . SeriesStudio = series . Studios . FirstOrDefault ( ) ;
series = series ? ? season . Series ;
if ( series ! = null )
{
dto . SeriesStudio = series . Studios . FirstOrDefault ( ) ;
}
}
if ( options . GetImageLimit ( ImageType . Primary ) > 0 )
if ( fields . Contains ( ItemFields . SeriesPrimaryImage ) )
{
series = series ? ? season . Series ;
if ( series ! = null )
{
dto . SeriesPrimaryImageTag = GetImageCacheTag ( series , ImageType . Primary ) ;
}
@ -1543,6 +1440,70 @@ namespace MediaBrowser.Server.Implementations.Dto
}
}
private void AddInheritedImages ( BaseItemDto dto , BaseItem item , DtoOptions options , BaseItem owner )
{
var logoLimit = options . GetImageLimit ( ImageType . Logo ) ;
var artLimit = options . GetImageLimit ( ImageType . Art ) ;
var thumbLimit = options . GetImageLimit ( ImageType . Thumb ) ;
var backdropLimit = options . GetImageLimit ( ImageType . Backdrop ) ;
if ( logoLimit = = 0 & & artLimit = = 0 & & thumbLimit = = 0 & & backdropLimit = = 0 )
{
return ;
}
BaseItem parent = null ;
var isFirst = true ;
while ( ( ( ! dto . HasLogo & & logoLimit > 0 ) | | ( ! dto . HasArtImage & & artLimit > 0 ) | | ( ! dto . HasThumb & & thumbLimit > 0 ) | | parent is Series ) & &
( parent = parent ? ? ( isFirst ? item . GetParent ( ) ? ? owner : parent ) ) ! = null )
{
if ( logoLimit > 0 & & ! dto . HasLogo & & dto . ParentLogoItemId = = null )
{
var image = parent . GetImageInfo ( ImageType . Logo , 0 ) ;
if ( image ! = null )
{
dto . ParentLogoItemId = GetDtoId ( parent ) ;
dto . ParentLogoImageTag = GetImageCacheTag ( parent , image ) ;
}
}
if ( artLimit > 0 & & ! dto . HasArtImage & & dto . ParentArtItemId = = null )
{
var image = parent . GetImageInfo ( ImageType . Art , 0 ) ;
if ( image ! = null )
{
dto . ParentArtItemId = GetDtoId ( parent ) ;
dto . ParentArtImageTag = GetImageCacheTag ( parent , image ) ;
}
}
if ( thumbLimit > 0 & & ! dto . HasThumb & & ( dto . ParentThumbItemId = = null | | parent is Series ) )
{
var image = parent . GetImageInfo ( ImageType . Thumb , 0 ) ;
if ( image ! = null )
{
dto . ParentThumbItemId = GetDtoId ( parent ) ;
dto . ParentThumbImageTag = GetImageCacheTag ( parent , image ) ;
}
}
if ( backdropLimit > 0 & & ! dto . HasBackdrop )
{
var images = parent . GetImages ( ImageType . Backdrop ) . Take ( backdropLimit ) . ToList ( ) ;
if ( images . Count > 0 )
{
dto . ParentBackdropItemId = GetDtoId ( parent ) ;
dto . ParentBackdropImageTags = GetImageTags ( parent , images ) ;
}
}
isFirst = false ;
parent = parent . GetParent ( ) ;
}
}
private string GetMappedPath ( IHasMetadata item )
{
var path = item . Path ;