2
0

ILocalImageProvider.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Drawing;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace MediaBrowser.Controller.Providers
  10. {
  11. /// <summary>
  12. /// This is just a marker interface
  13. /// </summary>
  14. public interface ILocalImageProvider : IImageProvider
  15. {
  16. }
  17. public interface ILocalImageFileProvider : ILocalImageProvider
  18. {
  19. List<LocalImageInfo> GetImages(IHasImages item, IDirectoryService directoryService);
  20. }
  21. public class LocalImageInfo
  22. {
  23. public FileSystemInfo FileInfo { get; set; }
  24. public ImageType Type { get; set; }
  25. }
  26. public interface IDynamicImageProvider : IImageProvider
  27. {
  28. /// <summary>
  29. /// Gets the supported images.
  30. /// </summary>
  31. /// <param name="item">The item.</param>
  32. /// <returns>IEnumerable{ImageType}.</returns>
  33. IEnumerable<ImageType> GetSupportedImages(IHasImages item);
  34. /// <summary>
  35. /// Gets the image.
  36. /// </summary>
  37. /// <param name="item">The item.</param>
  38. /// <param name="type">The type.</param>
  39. /// <param name="cancellationToken">The cancellation token.</param>
  40. /// <returns>Task{DynamicImageResponse}.</returns>
  41. Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken);
  42. }
  43. public class DynamicImageInfo
  44. {
  45. public string ImageId { get; set; }
  46. public ImageType Type { get; set; }
  47. }
  48. public class DynamicImageResponse
  49. {
  50. public string Path { get; set; }
  51. public Stream Stream { get; set; }
  52. public ImageFormat Format { get; set; }
  53. public bool HasImage { get; set; }
  54. public void SetFormatFromMimeType(string mimeType)
  55. {
  56. if (mimeType.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
  57. {
  58. Format = ImageFormat.Gif;
  59. }
  60. else if (mimeType.EndsWith("bmp", StringComparison.OrdinalIgnoreCase))
  61. {
  62. Format = ImageFormat.Bmp;
  63. }
  64. else if (mimeType.EndsWith("png", StringComparison.OrdinalIgnoreCase))
  65. {
  66. Format = ImageFormat.Png;
  67. }
  68. else
  69. {
  70. Format = ImageFormat.Jpg;
  71. }
  72. }
  73. }
  74. }