2015-03-14 13:02:51 -04:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2015-02-19 21:12:33 -05:00
|
|
|
|
using MediaBrowser.Common.IO;
|
2015-04-08 10:38:02 -04:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2015-03-13 15:52:49 -04:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-11-10 22:41:55 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2015-03-14 11:38:16 -04:00
|
|
|
|
using MediaBrowser.Server.Implementations.Photos;
|
2014-11-10 23:26:53 -05:00
|
|
|
|
using MoreLinq;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-03-14 13:02:51 -04:00
|
|
|
|
using System.Globalization;
|
2015-03-13 16:09:07 -04:00
|
|
|
|
using System.IO;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2015-03-14 11:38:16 -04:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.UserViews
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
2015-04-26 00:39:40 -04:00
|
|
|
|
public class DynamicImageProvider : BaseDynamicImageProvider<UserView>
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
|
|
|
|
private readonly IUserManager _userManager;
|
2014-11-10 23:26:53 -05:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
|
2015-04-08 11:45:30 -04:00
|
|
|
|
public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, IUserManager userManager, ILibraryManager libraryManager)
|
|
|
|
|
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
2015-03-06 22:53:31 -05:00
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_libraryManager = libraryManager;
|
2015-03-14 00:50:23 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
if (IsUsingCollectionStrip(view))
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary,
|
|
|
|
|
ImageType.Thumb
|
|
|
|
|
};
|
2014-10-29 18:01:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
|
|
|
|
|
if (!view.UserId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return new List<BaseItem>();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 11:38:16 -04:00
|
|
|
|
if (string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new List<BaseItem>();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 00:53:47 -04:00
|
|
|
|
if (string.Equals(view.ViewType, SpecialFolder.GameGenre, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
string.Equals(view.ViewType, SpecialFolder.MusicGenre, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
string.Equals(view.ViewType, SpecialFolder.MovieGenre, StringComparison.OrdinalIgnoreCase) ||
|
2014-11-10 23:26:53 -05:00
|
|
|
|
string.Equals(view.ViewType, SpecialFolder.TvGenre, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-04-17 00:53:47 -04:00
|
|
|
|
var userItemsResult = await view.GetItems(new InternalItemsQuery
|
2014-11-10 23:26:53 -05:00
|
|
|
|
{
|
2015-04-17 00:53:47 -04:00
|
|
|
|
User = _userManager.GetUserById(view.UserId.Value),
|
|
|
|
|
CollapseBoxSetItems = false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return userItemsResult.Items.ToList();
|
2014-11-10 23:26:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 00:50:23 -04:00
|
|
|
|
var isUsingCollectionStrip = IsUsingCollectionStrip(view);
|
2015-03-14 11:38:16 -04:00
|
|
|
|
var recursive = isUsingCollectionStrip && !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.ViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
2015-03-14 00:50:23 -04:00
|
|
|
|
|
2014-10-29 18:01:02 -04:00
|
|
|
|
var result = await view.GetItems(new InternalItemsQuery
|
|
|
|
|
{
|
2015-03-14 00:50:23 -04:00
|
|
|
|
User = _userManager.GetUserById(view.UserId.Value),
|
|
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
|
Recursive = recursive,
|
2015-04-03 12:58:12 -04:00
|
|
|
|
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" }
|
2014-10-29 18:01:02 -04:00
|
|
|
|
|
|
|
|
|
}).ConfigureAwait(false);
|
|
|
|
|
|
2014-11-10 22:41:55 -05: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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 15:52:49 -04:00
|
|
|
|
var audio = i as Audio;
|
|
|
|
|
if (audio != null)
|
|
|
|
|
{
|
2015-03-14 00:50:23 -04:00
|
|
|
|
var album = audio.FindParent<MusicAlbum>();
|
|
|
|
|
if (album != null && album.HasImage(ImageType.Primary))
|
2015-03-13 15:52:49 -04:00
|
|
|
|
{
|
2015-03-14 00:50:23 -04:00
|
|
|
|
return album;
|
2015-03-13 15:52:49 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 22:41:55 -05:00
|
|
|
|
return i;
|
|
|
|
|
|
|
|
|
|
}).DistinctBy(i => i.Id);
|
|
|
|
|
|
2015-03-14 00:50:23 -04:00
|
|
|
|
if (isUsingCollectionStrip)
|
2015-03-13 15:52:49 -04:00
|
|
|
|
{
|
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)).ToList(), 8);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 22:41:55 -05:00
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary)).ToList());
|
2014-10-29 18:01:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 15:37:19 -04:00
|
|
|
|
public override bool Supports(IHasImages item)
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
|
|
|
|
var view = item as UserView;
|
|
|
|
|
|
|
|
|
|
if (view != null && view.UserId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var supported = new[]
|
|
|
|
|
{
|
|
|
|
|
SpecialFolder.TvFavoriteEpisodes,
|
|
|
|
|
SpecialFolder.TvFavoriteSeries,
|
|
|
|
|
SpecialFolder.TvGenres,
|
2014-11-10 22:41:55 -05:00
|
|
|
|
SpecialFolder.TvGenre,
|
2014-10-29 18:01:02 -04:00
|
|
|
|
SpecialFolder.TvLatest,
|
|
|
|
|
SpecialFolder.TvNextUp,
|
|
|
|
|
SpecialFolder.TvResume,
|
|
|
|
|
SpecialFolder.TvShowSeries,
|
|
|
|
|
|
|
|
|
|
SpecialFolder.MovieCollections,
|
|
|
|
|
SpecialFolder.MovieFavorites,
|
|
|
|
|
SpecialFolder.MovieGenres,
|
2014-11-10 22:41:55 -05:00
|
|
|
|
SpecialFolder.MovieGenre,
|
2014-10-29 18:01:02 -04:00
|
|
|
|
SpecialFolder.MovieLatest,
|
|
|
|
|
SpecialFolder.MovieMovies,
|
|
|
|
|
SpecialFolder.MovieResume,
|
|
|
|
|
|
|
|
|
|
SpecialFolder.GameFavorites,
|
|
|
|
|
SpecialFolder.GameGenres,
|
2014-11-10 22:41:55 -05:00
|
|
|
|
SpecialFolder.GameGenre,
|
2014-10-29 18:01:02 -04:00
|
|
|
|
SpecialFolder.GameSystems,
|
|
|
|
|
SpecialFolder.LatestGames,
|
|
|
|
|
SpecialFolder.RecentlyPlayedGames,
|
|
|
|
|
|
|
|
|
|
SpecialFolder.MusicArtists,
|
|
|
|
|
SpecialFolder.MusicAlbumArtists,
|
|
|
|
|
SpecialFolder.MusicAlbums,
|
|
|
|
|
SpecialFolder.MusicGenres,
|
2014-11-10 22:41:55 -05:00
|
|
|
|
SpecialFolder.MusicGenre,
|
2014-10-29 18:01:02 -04:00
|
|
|
|
SpecialFolder.MusicLatest,
|
2015-04-13 01:12:02 -04:00
|
|
|
|
SpecialFolder.MusicPlaylists,
|
2014-10-29 18:01:02 -04:00
|
|
|
|
SpecialFolder.MusicSongs,
|
|
|
|
|
SpecialFolder.MusicFavorites,
|
|
|
|
|
SpecialFolder.MusicFavoriteArtists,
|
|
|
|
|
SpecialFolder.MusicFavoriteAlbums,
|
|
|
|
|
SpecialFolder.MusicFavoriteSongs
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-13 15:52:49 -04:00
|
|
|
|
return (IsUsingCollectionStrip(view) || supported.Contains(view.ViewType, StringComparer.OrdinalIgnoreCase)) &&
|
2014-10-29 18:01:02 -04:00
|
|
|
|
_userManager.GetUserById(view.UserId.Value) != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-13 15:52:49 -04:00
|
|
|
|
|
|
|
|
|
private bool IsUsingCollectionStrip(UserView view)
|
|
|
|
|
{
|
2015-03-14 00:50:23 -04:00
|
|
|
|
string[] collectionStripViewTypes =
|
|
|
|
|
{
|
|
|
|
|
CollectionType.Movies,
|
|
|
|
|
CollectionType.TvShows,
|
|
|
|
|
CollectionType.Games,
|
|
|
|
|
CollectionType.Music,
|
|
|
|
|
CollectionType.BoxSets,
|
|
|
|
|
CollectionType.Playlists,
|
2015-03-14 11:38:16 -04:00
|
|
|
|
CollectionType.Channels,
|
2015-03-15 21:48:25 -04:00
|
|
|
|
CollectionType.LiveTv,
|
|
|
|
|
CollectionType.Books,
|
2015-03-17 22:39:55 -04:00
|
|
|
|
CollectionType.Photos,
|
|
|
|
|
CollectionType.HomeVideos,
|
2015-03-18 12:40:16 -04:00
|
|
|
|
CollectionType.MusicVideos,
|
2015-03-17 22:39:55 -04:00
|
|
|
|
string.Empty
|
2015-03-14 00:50:23 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty);
|
2015-03-13 15:52:49 -04:00
|
|
|
|
}
|
2015-03-13 16:09:07 -04:00
|
|
|
|
|
2015-04-23 12:50:54 -04:00
|
|
|
|
protected override async Task<bool> CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPath, ImageType imageType, int imageIndex)
|
2015-03-13 16:09:07 -04:00
|
|
|
|
{
|
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
if (imageType == ImageType.Primary && IsUsingCollectionStrip(view))
|
|
|
|
|
{
|
2015-03-15 23:41:12 -04:00
|
|
|
|
if (itemsWithImages.Count == 0 && !string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-04-08 11:45:30 -04:00
|
|
|
|
return false;
|
2015-03-15 23:41:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-23 12:50:54 -04:00
|
|
|
|
await CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540, false, item.Name).ConfigureAwait(false);
|
2015-04-08 11:45:30 -04:00
|
|
|
|
return true;
|
2015-03-13 16:09:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-23 12:50:54 -04:00
|
|
|
|
return await base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex).ConfigureAwait(false);
|
2015-03-13 16:09:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 10:38:02 -04:00
|
|
|
|
protected override IEnumerable<String> GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable<BaseItem> items)
|
2015-03-13 16:09:07 -04:00
|
|
|
|
{
|
2015-04-08 10:38:02 -04:00
|
|
|
|
var userView = primaryItem as UserView;
|
|
|
|
|
|
|
|
|
|
if (userView != null && string.Equals(userView.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
2015-03-14 11:38:16 -04:00
|
|
|
|
{
|
|
|
|
|
var list = new List<string>();
|
|
|
|
|
for (int i = 1; i <= 8; i++)
|
|
|
|
|
{
|
|
|
|
|
list.Add(ExtractLiveTvResource(i.ToString(CultureInfo.InvariantCulture), ApplicationPaths));
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 10:38:02 -04:00
|
|
|
|
return base.GetStripCollageImagePaths(primaryItem, items);
|
2015-03-13 16:09:07 -04:00
|
|
|
|
}
|
2015-03-14 11:38:16 -04:00
|
|
|
|
|
|
|
|
|
private string ExtractLiveTvResource(string name, IApplicationPaths paths)
|
|
|
|
|
{
|
|
|
|
|
var namespacePath = GetType().Namespace + ".livetv." + name + ".jpg";
|
|
|
|
|
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".jpg");
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
|
|
|
|
|
|
|
|
|
|
using (var stream = GetType().Assembly.GetManifestResourceStream(namespacePath))
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
|
|
|
|
{
|
|
|
|
|
stream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tempPath;
|
|
|
|
|
}
|
2014-10-29 18:01:02 -04:00
|
|
|
|
}
|
|
|
|
|
}
|