You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
5.8 KiB
163 lines
5.8 KiB
using MediaBrowser.Common.Configuration;
|
|
using MediaBrowser.Controller.Drawing;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
using MediaBrowser.Controller.Providers;
|
|
using MediaBrowser.Model.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Emby.Server.Implementations.Images;
|
|
using MediaBrowser.Model.IO;
|
|
using MediaBrowser.Controller.Collections;
|
|
using MediaBrowser.Controller.Dto;
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
using MediaBrowser.Controller.IO;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Model.Extensions;
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
namespace Emby.Server.Implementations.UserViews
|
|
{
|
|
public class CollectionFolderImageProvider : BaseDynamicImageProvider<CollectionFolder>
|
|
{
|
|
public CollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
|
{
|
|
}
|
|
|
|
protected override List<BaseItem> GetItemsWithImages(IHasMetadata item)
|
|
{
|
|
var view = (CollectionFolder)item;
|
|
|
|
var recursive = !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
|
|
|
var result = view.GetItemList(new InternalItemsQuery
|
|
{
|
|
CollapseBoxSetItems = false,
|
|
Recursive = recursive,
|
|
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" },
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
});
|
|
|
|
var items = result.Select(i =>
|
|
{
|
|
var episode = i as Episode;
|
|
if (episode != null)
|
|
{
|
|
var series = episode.Series;
|
|
if (series != null)
|
|
{
|
|
return series;
|
|
}
|
|
|
|
return episode;
|
|
}
|
|
|
|
var season = i as Season;
|
|
if (season != null)
|
|
{
|
|
var series = season.Series;
|
|
if (series != null)
|
|
{
|
|
return series;
|
|
}
|
|
|
|
return season;
|
|
}
|
|
|
|
var audio = i as Audio;
|
|
if (audio != null)
|
|
{
|
|
var album = audio.AlbumEntity;
|
|
if (album != null && album.HasImage(ImageType.Primary))
|
|
{
|
|
return album;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
|
|
}).DistinctBy(i => i.Id);
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)), 8);
|
|
}
|
|
|
|
protected override bool Supports(IHasMetadata item)
|
|
{
|
|
return item is CollectionFolder;
|
|
}
|
|
|
|
protected override string CreateImage(IHasMetadata item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
|
{
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
if (imageType == ImageType.Primary)
|
|
{
|
|
if (itemsWithImages.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
|
|
}
|
|
|
|
return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex);
|
|
}
|
|
}
|
|
|
|
public class ManualCollectionFolderImageProvider : BaseDynamicImageProvider<ManualCollectionsFolder>
|
|
{
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
public ManualCollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
|
{
|
|
_libraryManager = libraryManager;
|
|
}
|
|
|
|
protected override List<BaseItem> GetItemsWithImages(IHasMetadata item)
|
|
{
|
|
var view = (ManualCollectionsFolder)item;
|
|
|
|
var recursive = !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
|
|
|
var items = _libraryManager.GetItemList(new InternalItemsQuery
|
|
{
|
|
Recursive = recursive,
|
|
IncludeItemTypes = new[] { typeof(BoxSet).Name },
|
|
Limit = 20,
|
|
OrderBy = new [] { new Tuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending) },
|
|
DtoOptions = new DtoOptions(false)
|
|
});
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)), 8);
|
|
}
|
|
|
|
protected override bool Supports(IHasMetadata item)
|
|
{
|
|
return item is ManualCollectionsFolder;
|
|
}
|
|
|
|
protected override string CreateImage(IHasMetadata item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
|
{
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
if (imageType == ImageType.Primary)
|
|
{
|
|
if (itemsWithImages.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
|
|
}
|
|
|
|
return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex);
|
|
}
|
|
}
|
|
|
|
}
|