jellyfin/Emby.Server.Implementations/UserViews/FolderImageProvider.cs

110 lines
4.1 KiB
C#
Raw Normal View History

2017-10-21 16:39:52 +00:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Emby.Server.Implementations.Images;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Dto;
namespace Emby.Server.Implementations.Photos
{
public abstract class BaseFolderImageProvider<T> : BaseDynamicImageProvider<T>
2018-09-12 17:26:21 +00:00
where T : Folder, new()
2017-10-21 16:39:52 +00:00
{
protected ILibraryManager _libraryManager;
public BaseFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager)
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
{
_libraryManager = libraryManager;
}
2018-09-12 17:26:21 +00:00
protected override List<BaseItem> GetItemsWithImages(BaseItem item)
2017-10-21 16:39:52 +00:00
{
return _libraryManager.GetItemList(new InternalItemsQuery
{
2018-09-12 17:26:21 +00:00
Parent = item,
2017-10-21 16:39:52 +00:00
DtoOptions = new DtoOptions(true),
2018-09-12 17:26:21 +00:00
ImageTypes = new ImageType[] { ImageType.Primary },
2019-01-07 23:27:46 +00:00
OrderBy = new System.ValueTuple<string, SortOrder>[]
2018-09-12 17:26:21 +00:00
{
new System.ValueTuple<string, SortOrder>(ItemSortBy.IsFolder, SortOrder.Ascending),
new System.ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending)
},
Limit = 1
2017-10-21 16:39:52 +00:00
});
}
2018-09-12 17:26:21 +00:00
protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
2017-10-21 16:39:52 +00:00
{
return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
}
2018-09-12 17:26:21 +00:00
protected override bool Supports(BaseItem item)
2017-10-21 16:39:52 +00:00
{
2018-09-12 17:26:21 +00:00
return item is T;
2017-10-21 16:39:52 +00:00
}
2018-09-12 17:26:21 +00:00
protected override bool HasChangedByDate(BaseItem item, ItemImageInfo image)
2017-10-21 16:39:52 +00:00
{
if (item is MusicAlbum)
{
return false;
}
return base.HasChangedByDate(item, image);
}
}
public class FolderImageProvider : BaseFolderImageProvider<Folder>
{
public FolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager)
: base(fileSystem, providerManager, applicationPaths, imageProcessor, libraryManager)
{
}
2018-09-12 17:26:21 +00:00
protected override bool Supports(BaseItem item)
{
if (item is PhotoAlbum || item is MusicAlbum)
{
return false;
}
var folder = item as Folder;
if (folder != null)
{
if (folder.IsTopParent)
{
return false;
}
}
return true;
//return item.SourceType == SourceType.Library;
}
2017-10-21 16:39:52 +00:00
}
public class MusicAlbumImageProvider : BaseFolderImageProvider<MusicAlbum>
{
public MusicAlbumImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager)
: base(fileSystem, providerManager, applicationPaths, imageProcessor, libraryManager)
{
}
}
public class PhotoAlbumImageProvider : BaseFolderImageProvider<PhotoAlbum>
{
public PhotoAlbumImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager)
: base(fileSystem, providerManager, applicationPaths, imageProcessor, libraryManager)
{
}
}
}