jellyfin/MediaBrowser.Server.Implementations/Photos/DynamicImageProvider.cs

171 lines
5.8 KiB
C#
Raw Normal View History

2014-10-29 22:01:02 +00:00
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
2014-11-11 03:41:55 +00:00
using MediaBrowser.Controller.Entities.TV;
2014-10-29 22:01:02 +00:00
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
2014-11-11 04:26:53 +00:00
using MoreLinq;
2014-10-29 22:01:02 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2014-11-11 04:26:53 +00:00
namespace MediaBrowser.Server.Implementations.Photos
2014-10-29 22:01:02 +00:00
{
public class MusicDynamicImageProvider : BaseDynamicImageProvider<UserView>, ICustomMetadataProvider<UserView>
{
private readonly IUserManager _userManager;
2014-11-11 04:26:53 +00:00
private readonly ILibraryManager _libraryManager;
2014-10-29 22:01:02 +00:00
2014-11-11 04:26:53 +00:00
public MusicDynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IUserManager userManager, ILibraryManager libraryManager)
2014-10-29 22:01:02 +00:00
: base(fileSystem, providerManager)
{
_userManager = userManager;
2014-11-11 04:26:53 +00:00
_libraryManager = libraryManager;
2014-10-29 22:01:02 +00:00
}
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
{
var view = (UserView)item;
if (!view.UserId.HasValue)
{
return new List<BaseItem>();
}
2014-11-11 04:26:53 +00:00
if (string.Equals(view.ViewType, SpecialFolder.GameGenre, StringComparison.OrdinalIgnoreCase))
{
var list = new List<BaseItem>();
var genre = _libraryManager.GetGameGenre(view.Name);
if (genre.HasImage(ImageType.Primary) || genre.HasImage(ImageType.Thumb))
{
list.Add(genre);
}
return list;
}
if (string.Equals(view.ViewType, SpecialFolder.MusicGenre, StringComparison.OrdinalIgnoreCase))
{
var list = new List<BaseItem>();
var genre = _libraryManager.GetMusicGenre(view.Name);
if (genre.HasImage(ImageType.Primary) || genre.HasImage(ImageType.Thumb))
{
list.Add(genre);
}
return list;
}
if (string.Equals(view.ViewType, SpecialFolder.MovieGenre, StringComparison.OrdinalIgnoreCase) ||
string.Equals(view.ViewType, SpecialFolder.TvGenre, StringComparison.OrdinalIgnoreCase))
{
var list = new List<BaseItem>();
var genre = _libraryManager.GetGenre(view.Name);
if (genre.HasImage(ImageType.Primary) || genre.HasImage(ImageType.Thumb))
{
list.Add(genre);
}
return list;
}
2014-10-29 22:01:02 +00:00
var result = await view.GetItems(new InternalItemsQuery
{
User = _userManager.GetUserById(view.UserId.Value)
}).ConfigureAwait(false);
2014-11-11 03:41:55 +00:00
var items = result.Items.Select(i =>
{
var episode = i as Episode;
if (episode != null)
{
var series = episode.Series;
if (series != null)
{
return series;
}
var episodeSeason = episode.Season;
if (episodeSeason != null)
{
return episodeSeason;
}
return episode;
}
var season = i as Season;
if (season != null)
{
var series = season.Series;
if (series != null)
{
return series;
}
return season;
}
return i;
}).DistinctBy(i => i.Id);
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary)).ToList());
2014-10-29 22:01:02 +00:00
}
protected override bool Supports(IHasImages item)
{
var view = item as UserView;
if (view != null && view.UserId.HasValue)
{
var supported = new[]
{
SpecialFolder.TvFavoriteEpisodes,
SpecialFolder.TvFavoriteSeries,
SpecialFolder.TvGenres,
2014-11-11 03:41:55 +00:00
SpecialFolder.TvGenre,
2014-10-29 22:01:02 +00:00
SpecialFolder.TvLatest,
SpecialFolder.TvNextUp,
SpecialFolder.TvResume,
SpecialFolder.TvShowSeries,
SpecialFolder.MovieCollections,
SpecialFolder.MovieFavorites,
SpecialFolder.MovieGenres,
2014-11-11 03:41:55 +00:00
SpecialFolder.MovieGenre,
2014-10-29 22:01:02 +00:00
SpecialFolder.MovieLatest,
SpecialFolder.MovieMovies,
SpecialFolder.MovieResume,
SpecialFolder.GameFavorites,
SpecialFolder.GameGenres,
2014-11-11 03:41:55 +00:00
SpecialFolder.GameGenre,
2014-10-29 22:01:02 +00:00
SpecialFolder.GameSystems,
SpecialFolder.LatestGames,
SpecialFolder.RecentlyPlayedGames,
SpecialFolder.MusicArtists,
SpecialFolder.MusicAlbumArtists,
SpecialFolder.MusicAlbums,
SpecialFolder.MusicGenres,
2014-11-11 03:41:55 +00:00
SpecialFolder.MusicGenre,
2014-10-29 22:01:02 +00:00
SpecialFolder.MusicLatest,
SpecialFolder.MusicSongs,
SpecialFolder.MusicFavorites,
SpecialFolder.MusicFavoriteArtists,
SpecialFolder.MusicFavoriteAlbums,
SpecialFolder.MusicFavoriteSongs
};
return supported.Contains(view.ViewType, StringComparer.OrdinalIgnoreCase) &&
_userManager.GetUserById(view.UserId.Value) != null;
}
return false;
}
}
}