mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
update dynamic image provider
This commit is contained in:
parent
caadb4f374
commit
63fb306916
@ -107,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
get { return "Dynamic Image Provider"; }
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateImageAsync(IHasImages item,
|
||||
protected virtual async Task<Stream> CreateImageAsync(IHasImages item,
|
||||
List<BaseItem> itemsWithImages,
|
||||
ImageType imageType,
|
||||
int imageIndex)
|
||||
@ -158,13 +158,19 @@ namespace MediaBrowser.Server.Implementations.Photos
|
||||
}
|
||||
|
||||
protected List<BaseItem> GetFinalItems(List<BaseItem> items)
|
||||
{
|
||||
// Rotate the images no more than once per week
|
||||
return GetFinalItems(items, 4);
|
||||
}
|
||||
|
||||
protected List<BaseItem> GetFinalItems(List<BaseItem> 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();
|
||||
}
|
||||
|
@ -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<List<BaseItem>> 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<MusicAlbum>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user