jellyfin/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs

118 lines
4.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using Emby.Server.Implementations.Images;
2017-09-04 19:28:22 +00:00
using MediaBrowser.Common.Configuration;
2015-04-08 14:38:02 +00:00
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
2014-08-12 02:59:51 +00:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
2014-08-12 02:59:51 +00:00
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
2014-08-12 02:59:51 +00:00
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying;
2014-08-12 02:59:51 +00:00
2016-11-03 07:14:14 +00:00
namespace Emby.Server.Implementations.Playlists
2014-08-12 02:59:51 +00:00
{
2015-03-13 19:16:34 +00:00
public class PlaylistImageProvider : BaseDynamicImageProvider<Playlist>
2014-08-12 02:59:51 +00:00
{
2015-04-08 14:38:02 +00:00
public PlaylistImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
2014-10-20 03:04:45 +00:00
{
2014-08-12 02:59:51 +00:00
}
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
2014-08-12 02:59:51 +00:00
{
var playlist = (Playlist)item;
2018-09-12 17:26:21 +00:00
return playlist.GetManageableItems()
2014-08-12 02:59:51 +00:00
.Select(i =>
{
var subItem = i.Item2;
var episode = subItem as Episode;
if (episode != null)
{
var series = episode.Series;
if (series != null && series.HasImage(ImageType.Primary))
{
return series;
}
}
if (subItem.HasImage(ImageType.Primary))
{
return subItem;
}
2018-09-12 17:26:21 +00:00
var parent = subItem.GetOwner() ?? subItem.GetParent();
2014-08-12 02:59:51 +00:00
if (parent != null && parent.HasImage(ImageType.Primary))
{
if (parent is MusicAlbum)
{
return parent;
}
}
return null;
})
.Where(i => i != null)
2019-02-02 11:27:06 +00:00
.GroupBy(x => x.Id)
.Select(x => x.First())
2018-09-12 17:26:21 +00:00
.ToList();
2014-10-20 03:04:45 +00:00
}
2014-08-12 02:59:51 +00:00
}
public class MusicGenreImageProvider : BaseDynamicImageProvider<MusicGenre>
{
private readonly ILibraryManager _libraryManager;
public MusicGenreImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
{
_libraryManager = libraryManager;
}
protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
2018-09-12 17:26:21 +00:00
return _libraryManager.GetItemList(new InternalItemsQuery
{
Genres = new[] { item.Name },
IncludeItemTypes = new[] { typeof(MusicAlbum).Name, typeof(MusicVideo).Name, typeof(Audio).Name },
2019-10-20 14:08:40 +00:00
OrderBy = new[] { (ItemSortBy.Random, SortOrder.Ascending) },
Limit = 4,
Recursive = true,
2017-05-21 07:25:49 +00:00
ImageTypes = new[] { ImageType.Primary },
DtoOptions = new DtoOptions(false)
});
}
}
2017-03-10 18:32:38 +00:00
public class GenreImageProvider : BaseDynamicImageProvider<Genre>
{
private readonly ILibraryManager _libraryManager;
public GenreImageProvider(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-03-10 18:32:38 +00:00
{
2018-09-12 17:26:21 +00:00
return _libraryManager.GetItemList(new InternalItemsQuery
2017-03-10 18:32:38 +00:00
{
Genres = new[] { item.Name },
IncludeItemTypes = new[] { typeof(Series).Name, typeof(Movie).Name },
2019-10-20 14:08:40 +00:00
OrderBy = new[] { (ItemSortBy.Random, SortOrder.Ascending) },
2017-03-10 18:32:38 +00:00
Limit = 4,
Recursive = true,
2017-05-21 07:25:49 +00:00
ImageTypes = new[] { ImageType.Primary },
DtoOptions = new DtoOptions(false)
});
2017-03-10 18:32:38 +00:00
}
}
2014-08-12 02:59:51 +00:00
}