PlaylistImageProvider.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Emby.Server.Implementations.Images;
  5. using MediaBrowser.Common.Configuration;
  6. using MediaBrowser.Controller.Drawing;
  7. using MediaBrowser.Controller.Dto;
  8. using MediaBrowser.Controller.Entities;
  9. using MediaBrowser.Controller.Entities.Audio;
  10. using MediaBrowser.Controller.Entities.Movies;
  11. using MediaBrowser.Controller.Entities.TV;
  12. using MediaBrowser.Controller.Library;
  13. using MediaBrowser.Controller.Playlists;
  14. using MediaBrowser.Controller.Providers;
  15. using MediaBrowser.Model.Entities;
  16. using MediaBrowser.Model.IO;
  17. using MediaBrowser.Model.Querying;
  18. namespace Emby.Server.Implementations.Playlists
  19. {
  20. public class PlaylistImageProvider : BaseDynamicImageProvider<Playlist>
  21. {
  22. public PlaylistImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
  23. {
  24. }
  25. protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
  26. {
  27. var playlist = (Playlist)item;
  28. return playlist.GetManageableItems()
  29. .Select(i =>
  30. {
  31. var subItem = i.Item2;
  32. var episode = subItem as Episode;
  33. if (episode != null)
  34. {
  35. var series = episode.Series;
  36. if (series != null && series.HasImage(ImageType.Primary))
  37. {
  38. return series;
  39. }
  40. }
  41. if (subItem.HasImage(ImageType.Primary))
  42. {
  43. return subItem;
  44. }
  45. var parent = subItem.GetOwner() ?? subItem.GetParent();
  46. if (parent != null && parent.HasImage(ImageType.Primary))
  47. {
  48. if (parent is MusicAlbum)
  49. {
  50. return parent;
  51. }
  52. }
  53. return null;
  54. })
  55. .Where(i => i != null)
  56. .GroupBy(x => x.Id)
  57. .Select(x => x.First())
  58. .ToList();
  59. }
  60. }
  61. public class MusicGenreImageProvider : BaseDynamicImageProvider<MusicGenre>
  62. {
  63. private readonly ILibraryManager _libraryManager;
  64. public MusicGenreImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
  65. {
  66. _libraryManager = libraryManager;
  67. }
  68. protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
  69. {
  70. return _libraryManager.GetItemList(new InternalItemsQuery
  71. {
  72. Genres = new[] { item.Name },
  73. IncludeItemTypes = new[] { typeof(MusicAlbum).Name, typeof(MusicVideo).Name, typeof(Audio).Name },
  74. OrderBy = new[] { (ItemSortBy.Random, SortOrder.Ascending) },
  75. Limit = 4,
  76. Recursive = true,
  77. ImageTypes = new[] { ImageType.Primary },
  78. DtoOptions = new DtoOptions(false)
  79. });
  80. }
  81. }
  82. public class GenreImageProvider : BaseDynamicImageProvider<Genre>
  83. {
  84. private readonly ILibraryManager _libraryManager;
  85. public GenreImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, ILibraryManager libraryManager) : base(fileSystem, providerManager, applicationPaths, imageProcessor)
  86. {
  87. _libraryManager = libraryManager;
  88. }
  89. protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
  90. {
  91. return _libraryManager.GetItemList(new InternalItemsQuery
  92. {
  93. Genres = new[] { item.Name },
  94. IncludeItemTypes = new[] { typeof(Series).Name, typeof(Movie).Name },
  95. OrderBy = new[] { (ItemSortBy.Random, SortOrder.Ascending) },
  96. Limit = 4,
  97. Recursive = true,
  98. ImageTypes = new[] { ImageType.Primary },
  99. DtoOptions = new DtoOptions(false)
  100. });
  101. }
  102. }
  103. }