dlna genre images
This commit is contained in:
parent
1fea9ad926
commit
0dfac392e7
|
@ -219,7 +219,7 @@
|
|||
<Compile Include="LiveTv\RefreshChannelsScheduledTask.cs" />
|
||||
<Compile Include="Localization\LocalizationManager.cs" />
|
||||
<Compile Include="MediaEncoder\EncodingManager.cs" />
|
||||
<Compile Include="Music\MusicDynamicImageProvider.cs" />
|
||||
<Compile Include="Photos\DynamicImageProvider.cs" />
|
||||
<Compile Include="News\NewsEntryPoint.cs" />
|
||||
<Compile Include="News\NewsService.cs" />
|
||||
<Compile Include="Notifications\CoreNotificationTypes.cs" />
|
||||
|
|
|
@ -6,8 +6,6 @@ using MediaBrowser.Controller.Providers;
|
|||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -74,36 +72,48 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
MetadataRefreshOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var img = await CreateImageAsync(item, itemsWithImages, imageType, 0).ConfigureAwait(false);
|
||||
var stream = await CreateImageAsync(item, itemsWithImages, imageType, 0).ConfigureAwait(false);
|
||||
|
||||
if (img == null)
|
||||
if (stream == null)
|
||||
{
|
||||
return ItemUpdateType.None;
|
||||
}
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
if (stream is MemoryStream)
|
||||
{
|
||||
img.Save(ms, ImageFormat.Png);
|
||||
using (stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
|
||||
ms.Position = 0;
|
||||
await ProviderManager.SaveImage(item, stream, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
await stream.CopyToAsync(ms).ConfigureAwait(false);
|
||||
|
||||
await ProviderManager.SaveImage(item, ms, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
||||
ms.Position = 0;
|
||||
|
||||
await ProviderManager.SaveImage(item, ms, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
return ItemUpdateType.ImageUpdate;
|
||||
}
|
||||
|
||||
protected Task<Image> GetThumbCollage(List<BaseItem> items)
|
||||
protected Task<Stream> GetThumbCollage(List<BaseItem> items)
|
||||
{
|
||||
return DynamicImageHelpers.GetThumbCollage(items.Select(i => i.GetImagePath(ImageType.Primary)).ToList(),
|
||||
return DynamicImageHelpers.GetThumbCollage(items.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb)).ToList(),
|
||||
FileSystem,
|
||||
1600,
|
||||
900);
|
||||
}
|
||||
|
||||
protected Task<Image> GetSquareCollage(List<BaseItem> items)
|
||||
protected Task<Stream> GetSquareCollage(List<BaseItem> items)
|
||||
{
|
||||
return DynamicImageHelpers.GetSquareCollage(items.Select(i => i.GetImagePath(ImageType.Primary)).ToList(),
|
||||
return DynamicImageHelpers.GetSquareCollage(items.Select(i => i.GetImagePath(ImageType.Primary) ?? i.GetImagePath(ImageType.Thumb)).ToList(),
|
||||
FileSystem,
|
||||
800);
|
||||
}
|
||||
|
@ -113,7 +123,7 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
get { return "Dynamic Image Provider"; }
|
||||
}
|
||||
|
||||
public async Task<Image> CreateImageAsync(IHasImages item,
|
||||
public async Task<Stream> CreateImageAsync(IHasImages item,
|
||||
List<BaseItem> itemsWithImages,
|
||||
ImageType imageType,
|
||||
int imageIndex)
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
{
|
||||
public static class DynamicImageHelpers
|
||||
{
|
||||
public static async Task<Image> GetThumbCollage(List<string> files,
|
||||
public static async Task<Stream> GetThumbCollage(List<string> files,
|
||||
IFileSystem fileSystem,
|
||||
int width,
|
||||
int height)
|
||||
|
@ -23,8 +23,8 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
const int rows = 1;
|
||||
const int cols = 3;
|
||||
|
||||
int cellWidth = 2 * (width / 3);
|
||||
int cellHeight = height;
|
||||
int cellWidth = 2 * (width / 3);
|
||||
int cellHeight = height;
|
||||
var index = 0;
|
||||
|
||||
var img = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
|
||||
|
@ -67,10 +67,10 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
return GetStream(img);
|
||||
}
|
||||
|
||||
public static async Task<Image> GetSquareCollage(List<string> files,
|
||||
|
||||
public static async Task<Stream> GetSquareCollage(List<string> files,
|
||||
IFileSystem fileSystem,
|
||||
int size)
|
||||
{
|
||||
|
@ -122,12 +122,23 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
return GetStream(img);
|
||||
}
|
||||
|
||||
private static Task<Image> GetSingleImage(List<string> files, IFileSystem fileSystem)
|
||||
private static Task<Stream> GetSingleImage(List<string> files, IFileSystem fileSystem)
|
||||
{
|
||||
return GetImage(files[0], fileSystem);
|
||||
return Task.FromResult<Stream>(fileSystem.GetFileStream(files[0], FileMode.Open, FileAccess.Read, FileShare.Read));
|
||||
}
|
||||
|
||||
private static Stream GetStream(Image image)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
|
||||
image.Save(ms, ImageFormat.Png);
|
||||
|
||||
ms.Position = 0;
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
private static async Task<Image> GetImage(string file, IFileSystem fileSystem)
|
||||
|
|
|
@ -4,23 +4,24 @@ using MediaBrowser.Controller.Entities.TV;
|
|||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Server.Implementations.Photos;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MoreLinq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Music
|
||||
namespace MediaBrowser.Server.Implementations.Photos
|
||||
{
|
||||
public class MusicDynamicImageProvider : BaseDynamicImageProvider<UserView>, ICustomMetadataProvider<UserView>
|
||||
{
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public MusicDynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IUserManager userManager)
|
||||
public MusicDynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IUserManager userManager, ILibraryManager libraryManager)
|
||||
: base(fileSystem, providerManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
protected override async Task<List<BaseItem>> GetItemsWithImages(IHasImages item)
|
||||
|
@ -32,6 +33,44 @@ namespace MediaBrowser.Server.Implementations.Music
|
|||
return new List<BaseItem>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
var result = await view.GetItems(new InternalItemsQuery
|
||||
{
|
||||
User = _userManager.GetUserById(view.UserId.Value)
|
Loading…
Reference in New Issue
Block a user