From 63fb306916294366884e28589361eb59c5b7b051 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Mar 2015 15:52:49 -0400 Subject: [PATCH] update dynamic image provider --- .../Photos/BaseDynamicImageProvider.cs | 10 ++++-- .../Photos/DynamicImageProvider.cs | 32 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs index fd87bd16a..4a347f130 100644 --- a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs @@ -107,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Photos get { return "Dynamic Image Provider"; } } - public async Task CreateImageAsync(IHasImages item, + protected virtual async Task CreateImageAsync(IHasImages item, List itemsWithImages, ImageType imageType, int imageIndex) @@ -158,13 +158,19 @@ namespace MediaBrowser.Server.Implementations.Photos } protected List GetFinalItems(List items) + { + // Rotate the images no more than once per week + return GetFinalItems(items, 4); + } + + protected List GetFinalItems(List items, int limit) { // Rotate the images no more than once per week var random = new Random(GetWeekOfYear()).Next(); return items .OrderBy(i => random - items.IndexOf(i)) - .Take(4) + .Take(limit) .OrderBy(i => i.Name) .ToList(); } diff --git a/MediaBrowser.Server.Implementations/Photos/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/Photos/DynamicImageProvider.cs index 58834b342..d4d9a9f14 100644 --- a/MediaBrowser.Server.Implementations/Photos/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Photos/DynamicImageProvider.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; @@ -18,10 +19,12 @@ namespace MediaBrowser.Server.Implementations.Photos private readonly IUserManager _userManager; private readonly ILibraryManager _libraryManager; - public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IUserManager userManager, ILibraryManager libraryManager) : base(fileSystem, providerManager, applicationPaths) + public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IUserManager userManager, ILibraryManager libraryManager, string[] collectionStripViewTypes) + : base(fileSystem, providerManager, applicationPaths) { _userManager = userManager; _libraryManager = libraryManager; + _collectionStripViewTypes = collectionStripViewTypes; } protected override async Task> GetItemsWithImages(IHasImages item) @@ -108,13 +111,33 @@ namespace MediaBrowser.Server.Implementations.Photos return season; } + var audio = i as Audio; + if (audio != null) + { + if (!audio.HasImage(ImageType.Primary)) + { + var album = audio.FindParent(); + if (album != null) + { + return album; + } + } + } + return i; }).DistinctBy(i => i.Id); + if (IsUsingCollectionStrip(view)) + { + return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)).ToList(), 8); + } + return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary)).ToList()); } + private readonly string[] _collectionStripViewTypes = { CollectionType.Movies }; + public override bool Supports(IHasImages item) { var view = item as UserView; @@ -160,11 +183,16 @@ namespace MediaBrowser.Server.Implementations.Photos SpecialFolder.MusicFavoriteSongs }; - return supported.Contains(view.ViewType, StringComparer.OrdinalIgnoreCase) && + return (IsUsingCollectionStrip(view) || supported.Contains(view.ViewType, StringComparer.OrdinalIgnoreCase)) && _userManager.GetUserById(view.UserId.Value) != null; } return false; } + + private bool IsUsingCollectionStrip(UserView view) + { + return _collectionStripViewTypes.Contains(view.ViewType ?? string.Empty); + } } }