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

107 lines
4.0 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Emby.Server.Implementations.Images;
using MediaBrowser.Common.Configuration;
2017-10-21 16:39:52 +00:00
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
2017-10-21 16:39:52 +00:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
2017-10-21 16:39:52 +00:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
2017-10-21 16:39:52 +00:00
using MediaBrowser.Model.Querying;
namespace Emby.Server.Implementations.UserViews
2017-10-21 16:39:52 +00:00
{
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;
}
protected override IReadOnlyList<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
});
}
protected override string CreateImage(BaseItem item, IReadOnlyCollection<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)
{
}
}
}