2015-03-14 13:02:51 -04:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
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;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2015-10-26 01:29:32 -04:00
|
|
|
|
using System.IO;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-03 03:14:14 -04:00
|
|
|
|
using Emby.Server.Implementations.Images;
|
2016-10-25 15:02:04 -04:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-09-04 11:01:31 -04:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2016-10-21 22:08:34 -04:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
|
2016-11-03 03:14:14 -04:00
|
|
|
|
namespace Emby.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;
|
2016-09-04 11:01:31 -04:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-10-29 18:01:02 -04:00
|
|
|
|
|
2016-09-04 11:01:31 -04:00
|
|
|
|
public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, IUserManager userManager, ILibraryManager libraryManager)
|
2015-04-08 11:45:30 -04:00
|
|
|
|
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
2015-03-06 22:53:31 -05:00
|
|
|
|
_userManager = userManager;
|
2016-09-04 11:01:31 -04:00
|
|
|
|
_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>
|
|
|
|
|
|
{
|
2015-06-27 23:29:50 -04:00
|
|
|
|
ImageType.Primary
|
2015-03-14 00:50:23 -04:00
|
|
|
|
};
|
2014-10-29 18:01:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
|
|
|
|
|
|
{
|
|
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
|
|
2015-03-14 11:38:16 -04:00
|
|
|
|
if (string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
{
|
2016-09-04 11:01:31 -04:00
|
|
|
|
var programs = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
|
|
{
|
|
|
|
|
|
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
|
|
|
|
|
|
ImageTypes = new[] { ImageType.Primary },
|
|
|
|
|
|
Limit = 30,
|
|
|
|
|
|
IsMovie = true
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return GetFinalItems(programs).ToList();
|
2015-03-14 11:38:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-09 13:18:37 -05:00
|
|
|
|
if (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
|
|
|
|
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-09-15 14:09:44 -04:00
|
|
|
|
var recursive = isUsingCollectionStrip && !new[] { CollectionType.Channels, CollectionType.BoxSets, CollectionType.Playlists }.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
|
|
|
|
|
|
{
|
2016-03-27 23:11:27 +02:00
|
|
|
|
User = view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null,
|
2015-03-14 00:50:23 -04:00
|
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
|
|
Recursive = recursive,
|
2016-08-09 01:08:21 -04:00
|
|
|
|
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Person" },
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-05-04 10:35:38 -04:00
|
|
|
|
var album = audio.AlbumEntity;
|
2015-03-14 00:50:23 -04:00
|
|
|
|
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-10-14 01:02:30 -04:00
|
|
|
|
protected override bool Supports(IHasImages item)
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
|
|
|
|
|
var view = item as UserView;
|
2015-07-27 01:03:34 -04:00
|
|
|
|
if (view != null)
|
2014-10-29 18:01:02 -04:00
|
|
|
|
{
|
2016-03-27 23:11:27 +02:00
|
|
|
|
return IsUsingCollectionStrip(view);
|
2014-10-29 18:01:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
2015-09-15 14:09:44 -04:00
|
|
|
|
CollectionType.Music,
|
|
|
|
|
|
CollectionType.Games,
|
|
|
|
|
|
CollectionType.Books,
|
|
|
|
|
|
CollectionType.MusicVideos,
|
|
|
|
|
|
CollectionType.HomeVideos,
|
|
|
|
|
|
CollectionType.BoxSets,
|
2016-09-04 11:01:31 -04:00
|
|
|
|
CollectionType.LiveTv,
|
2015-09-15 14:09:44 -04:00
|
|
|
|
CollectionType.Playlists,
|
2016-05-03 22:29:24 -04:00
|
|
|
|
CollectionType.Photos,
|
|
|
|
|
|
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-10-26 01:29:32 -04:00
|
|
|
|
protected override async Task<string> CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
2015-03-13 16:09:07 -04:00
|
|
|
|
{
|
2015-10-26 01:29:32 -04:00
|
|
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
|
|
|
2015-03-13 16:09:07 -04:00
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
|
if (imageType == ImageType.Primary && IsUsingCollectionStrip(view))
|
|
|
|
|
|
{
|
2015-08-28 00:19:08 -04:00
|
|
|
|
if (itemsWithImages.Count == 0)
|
2015-03-15 23:41:12 -04:00
|
|
|
|
{
|
2015-10-26 01:29:32 -04:00
|
|
|
|
return null;
|
2015-03-15 23:41:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-14 13:24:07 -04:00
|
|
|
|
return await CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540).ConfigureAwait(false);
|
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
|
|
|
|
}
|
2014-10-29 18:01:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|