2015-07-26 22:03:34 -07:00
|
|
|
|
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;
|
2015-10-25 22:29:32 -07:00
|
|
|
|
using System.IO;
|
2015-07-26 22:03:34 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-03 00:14:14 -07:00
|
|
|
|
using Emby.Server.Implementations.Images;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-09-05 13:07:36 -07:00
|
|
|
|
using MediaBrowser.Controller.Collections;
|
2017-05-21 00:25:49 -07:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2016-09-05 13:07:36 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2016-09-05 13:07:36 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-10-21 19:08:34 -07:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2016-09-05 13:07:36 -07:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2015-07-26 22:03:34 -07:00
|
|
|
|
|
2016-11-03 00:14:14 -07:00
|
|
|
|
namespace Emby.Server.Implementations.UserViews
|
2015-07-26 22:03:34 -07:00
|
|
|
|
{
|
|
|
|
|
public class CollectionFolderImageProvider : BaseDynamicImageProvider<CollectionFolder>
|
|
|
|
|
{
|
|
|
|
|
public CollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
var view = (CollectionFolder)item;
|
|
|
|
|
|
|
|
|
|
var recursive = !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
var result = await view.GetItems(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
|
Recursive = recursive,
|
2017-05-21 00:25:49 -07:00
|
|
|
|
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" },
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
2015-07-26 22:03:34 -07:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var items = result.Items.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)).ToList(), 8);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-13 22:02:30 -07:00
|
|
|
|
protected override bool Supports(IHasImages item)
|
2015-07-26 22:03:34 -07:00
|
|
|
|
{
|
|
|
|
|
return item is CollectionFolder;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 10:09:37 -07:00
|
|
|
|
protected override string CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
2015-07-26 22:03:34 -07:00
|
|
|
|
{
|
2015-10-25 22:29:32 -07:00
|
|
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
|
|
2015-07-26 22:03:34 -07:00
|
|
|
|
if (imageType == ImageType.Primary)
|
|
|
|
|
{
|
|
|
|
|
if (itemsWithImages.Count == 0)
|
|
|
|
|
{
|
2015-10-25 22:29:32 -07:00
|
|
|
|
return null;
|
2015-07-26 22:03:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 10:09:37 -07:00
|
|
|
|
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
|
2015-07-26 22:03:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 10:09:37 -07:00
|
|
|
|
return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex);
|
2015-07-26 22:03:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-05 13:07:36 -07:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages 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,
|
2017-05-21 00:25:49 -07:00
|
|
|
|
SortBy = new[] { ItemSortBy.Random },
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
2016-09-05 13:07:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)).ToList(), 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return item is ManualCollectionsFolder;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 10:09:37 -07:00
|
|
|
|
protected override string CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
2016-09-05 13:07:36 -07:00
|
|
|
|
{
|
|
|
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
|
|
|
|
|
|
if (imageType == ImageType.Primary)
|
|
|
|
|
{
|
|
|
|
|
if (itemsWithImages.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 10:09:37 -07:00
|
|
|
|
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
|
2016-09-05 13:07:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 10:09:37 -07:00
|
|
|
|
return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex);
|
2016-09-05 13:07:36 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-26 22:03:34 -07:00
|
|
|
|
}
|