2015-03-14 17:02:51 +00:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2015-04-08 14:38:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
2014-10-29 22:01:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2015-03-13 19:52:49 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
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;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-10-26 05:29:32 +00:00
|
|
|
|
using System.IO;
|
2014-10-29 22:01:02 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-03 07:14:14 +00:00
|
|
|
|
using Emby.Server.Implementations.Images;
|
2017-05-21 07:25:49 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-09-04 15:01:31 +00:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2016-10-22 02:08:34 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2014-10-29 22:01:02 +00:00
|
|
|
|
|
2016-11-03 07:14:14 +00:00
|
|
|
|
namespace Emby.Server.Implementations.UserViews
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
2015-04-26 04:39:40 +00:00
|
|
|
|
public class DynamicImageProvider : BaseDynamicImageProvider<UserView>
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IUserManager _userManager;
|
2016-09-04 15:01:31 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-10-29 22:01:02 +00:00
|
|
|
|
|
2016-09-04 15:01:31 +00:00
|
|
|
|
public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, IUserManager userManager, ILibraryManager libraryManager)
|
2015-04-08 15:45:30 +00:00
|
|
|
|
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
2015-03-07 03:53:31 +00:00
|
|
|
|
_userManager = userManager;
|
2016-09-04 15:01:31 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2015-03-14 04:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 21:06:13 +00:00
|
|
|
|
protected override List<BaseItem> GetItemsWithImages(IHasMetadata item)
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
|
|
|
|
var view = (UserView)item;
|
|
|
|
|
|
2015-03-14 15:38:16 +00:00
|
|
|
|
if (string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-09-04 15:01:31 +00:00
|
|
|
|
var programs = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
|
|
|
|
|
ImageTypes = new[] { ImageType.Primary },
|
|
|
|
|
Limit = 30,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
IsMovie = true,
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
});
|
2016-09-04 15:01:31 +00:00
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
return GetFinalItems(programs);
|
2015-03-14 15:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 18:18:37 +00:00
|
|
|
|
if (string.Equals(view.ViewType, SpecialFolder.MovieGenre, StringComparison.OrdinalIgnoreCase) ||
|
2014-11-11 04:26:53 +00:00
|
|
|
|
string.Equals(view.ViewType, SpecialFolder.TvGenre, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2017-08-01 16:45:57 +00:00
|
|
|
|
var userItemsResult = view.GetItemList(new InternalItemsQuery
|
2014-11-11 04:26:53 +00:00
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
2015-04-17 04:53:47 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-08-01 16:45:57 +00:00
|
|
|
|
return userItemsResult.ToList();
|
2014-11-11 04:26:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
var isUsingCollectionStrip = IsUsingCollectionStrip(view);
|
2015-09-15 18:09:44 +00:00
|
|
|
|
var recursive = isUsingCollectionStrip && !new[] { CollectionType.Channels, CollectionType.BoxSets, CollectionType.Playlists }.Contains(view.ViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
|
2015-03-14 04:50:23 +00:00
|
|
|
|
|
2017-08-01 16:45:57 +00:00
|
|
|
|
var result = view.GetItemList(new InternalItemsQuery
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
2016-03-27 21:11:27 +00:00
|
|
|
|
User = view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null,
|
2015-03-14 04:50:23 +00:00
|
|
|
|
CollapseBoxSetItems = false,
|
|
|
|
|
Recursive = recursive,
|
2016-08-09 05:08:21 +00:00
|
|
|
|
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Person" },
|
2017-05-21 07:25:49 +00:00
|
|
|
|
DtoOptions = new DtoOptions(false)
|
2017-05-26 06:48:54 +00:00
|
|
|
|
});
|
2014-10-29 22:01:02 +00:00
|
|
|
|
|
2017-08-01 16:45:57 +00:00
|
|
|
|
var items = result.Select(i =>
|
2014-11-11 03:41:55 +00:00
|
|
|
|
{
|
|
|
|
|
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 19:52:49 +00:00
|
|
|
|
var audio = i as Audio;
|
|
|
|
|
if (audio != null)
|
|
|
|
|
{
|
2015-05-04 14:35:38 +00:00
|
|
|
|
var album = audio.AlbumEntity;
|
2015-03-14 04:50:23 +00:00
|
|
|
|
if (album != null && album.HasImage(ImageType.Primary))
|
2015-03-13 19:52:49 +00:00
|
|
|
|
{
|
2015-03-14 04:50:23 +00:00
|
|
|
|
return album;
|
2015-03-13 19:52:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return i;
|
|
|
|
|
|
|
|
|
|
}).DistinctBy(i => i.Id);
|
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
if (isUsingCollectionStrip)
|
2015-03-13 19:52:49 +00:00
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)), 8);
|
2015-03-13 19:52:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary)));
|
2014-10-29 22:01:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 21:06:13 +00:00
|
|
|
|
protected override bool Supports(IHasMetadata item)
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
|
|
|
|
var view = item as UserView;
|
2015-07-27 05:03:34 +00:00
|
|
|
|
if (view != null)
|
2014-10-29 22:01:02 +00:00
|
|
|
|
{
|
2016-03-27 21:11:27 +00:00
|
|
|
|
return IsUsingCollectionStrip(view);
|
2014-10-29 22:01:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-03-13 19:52:49 +00:00
|
|
|
|
|
|
|
|
|
private bool IsUsingCollectionStrip(UserView view)
|
|
|
|
|
{
|
2015-03-14 04:50:23 +00:00
|
|
|
|
string[] collectionStripViewTypes =
|
|
|
|
|
{
|
|
|
|
|
CollectionType.Movies,
|
2017-01-11 17:56:26 +00:00
|
|
|
|
CollectionType.TvShows,
|
|
|
|
|
CollectionType.Playlists,
|
|
|
|
|
CollectionType.Photos
|
2015-03-14 04:50:23 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty);
|
2015-03-13 19:52:49 +00:00
|
|
|
|
}
|
2015-03-13 20:09:07 +00:00
|
|
|
|
|
2017-08-07 21:06:13 +00:00
|
|
|
|
protected override string CreateImage(IHasMetadata item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
2015-03-13 20:09:07 +00:00
|
|
|
|
{
|
2016-12-02 20:45:11 +00:00
|
|
|
|
if (itemsWithImages.Count == 0)
|
2015-03-13 20:09:07 +00:00
|
|
|
|
{
|
2016-12-02 20:45:11 +00:00
|
|
|
|
return null;
|
2015-03-13 20:09:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 20:45:11 +00:00
|
|
|
|
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
|
|
|
|
|
|
2017-05-19 17:09:37 +00:00
|
|
|
|
return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
|
2015-03-13 20:09:07 +00:00
|
|
|
|
}
|
2014-10-29 22:01:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|