CollectionFolderImageProvider.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using Jellyfin.Data.Enums;
  7. using MediaBrowser.Common.Configuration;
  8. using MediaBrowser.Controller.Drawing;
  9. using MediaBrowser.Controller.Dto;
  10. using MediaBrowser.Controller.Entities;
  11. using MediaBrowser.Controller.Providers;
  12. using MediaBrowser.Model.Entities;
  13. using MediaBrowser.Model.IO;
  14. using MediaBrowser.Model.Querying;
  15. namespace Emby.Server.Implementations.Images
  16. {
  17. public class CollectionFolderImageProvider : BaseDynamicImageProvider<CollectionFolder>
  18. {
  19. public CollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
  20. {
  21. }
  22. protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
  23. {
  24. var view = (CollectionFolder)item;
  25. var viewType = view.CollectionType;
  26. string[] includeItemTypes;
  27. if (string.Equals(viewType, CollectionType.Movies))
  28. {
  29. includeItemTypes = new string[] { "Movie" };
  30. }
  31. else if (string.Equals(viewType, CollectionType.TvShows))
  32. {
  33. includeItemTypes = new string[] { "Series" };
  34. }
  35. else if (string.Equals(viewType, CollectionType.Music))
  36. {
  37. includeItemTypes = new string[] { "MusicAlbum" };
  38. }
  39. else if (string.Equals(viewType, CollectionType.Books))
  40. {
  41. includeItemTypes = new string[] { "Book", "AudioBook" };
  42. }
  43. else if (string.Equals(viewType, CollectionType.BoxSets))
  44. {
  45. includeItemTypes = new string[] { "BoxSet" };
  46. }
  47. else if (string.Equals(viewType, CollectionType.HomeVideos) || string.Equals(viewType, CollectionType.Photos))
  48. {
  49. includeItemTypes = new string[] { "Video", "Photo" };
  50. }
  51. else
  52. {
  53. includeItemTypes = new string[] { "Video", "Audio", "Photo", "Movie", "Series" };
  54. }
  55. var recursive = !string.Equals(CollectionType.Playlists, viewType, StringComparison.OrdinalIgnoreCase);
  56. return view.GetItemList(new InternalItemsQuery
  57. {
  58. CollapseBoxSetItems = false,
  59. Recursive = recursive,
  60. DtoOptions = new DtoOptions(false),
  61. ImageTypes = new ImageType[] { ImageType.Primary },
  62. Limit = 8,
  63. OrderBy = new ValueTuple<string, SortOrder>[]
  64. {
  65. new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending)
  66. },
  67. IncludeItemTypes = includeItemTypes
  68. });
  69. }
  70. protected override bool Supports(BaseItem item)
  71. {
  72. return item is CollectionFolder;
  73. }
  74. protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
  75. {
  76. var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
  77. if (imageType == ImageType.Primary)
  78. {
  79. if (itemsWithImages.Count == 0)
  80. {
  81. return null;
  82. }
  83. return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540);
  84. }
  85. return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex);
  86. }
  87. }
  88. }