CollectionFolderImageProvider.cs 3.8 KB

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