jellyfin/MediaBrowser.Controller/Providers/ILocalImageProvider.cs

83 lines
2.4 KiB
C#
Raw Normal View History

2014-11-29 19:51:30 +00:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Entities;
2014-02-11 21:41:01 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers
{
/// <summary>
/// This is just a marker interface
/// </summary>
public interface ILocalImageProvider : IImageProvider
{
}
2014-02-08 20:02:35 +00:00
public interface ILocalImageFileProvider : ILocalImageProvider
{
2014-02-10 18:39:41 +00:00
List<LocalImageInfo> GetImages(IHasImages item, IDirectoryService directoryService);
}
public class LocalImageInfo
{
public FileSystemInfo FileInfo { get; set; }
public ImageType Type { get; set; }
}
public interface IDynamicImageProvider : IImageProvider
{
/// <summary>
/// Gets the supported images.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>IEnumerable{ImageType}.</returns>
IEnumerable<ImageType> GetSupportedImages(IHasImages item);
/// <summary>
/// Gets the image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="type">The type.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{DynamicImageResponse}.</returns>
Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken);
}
public class DynamicImageInfo
{
public string ImageId { get; set; }
public ImageType Type { get; set; }
}
public class DynamicImageResponse
{
public string Path { get; set; }
public Stream Stream { get; set; }
public ImageFormat Format { get; set; }
public bool HasImage { get; set; }
public void SetFormatFromMimeType(string mimeType)
{
2014-02-11 21:41:01 +00:00
if (mimeType.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
{
Format = ImageFormat.Gif;
}
else if (mimeType.EndsWith("bmp", StringComparison.OrdinalIgnoreCase))
{
Format = ImageFormat.Bmp;
}
else if (mimeType.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
Format = ImageFormat.Png;
}
else
{
Format = ImageFormat.Jpg;
}
}
}
}