| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | using Emby.Server.Implementations.Images; |
| | | 4 | | using MediaBrowser.Common.Configuration; |
| | | 5 | | using MediaBrowser.Controller.Drawing; |
| | | 6 | | using MediaBrowser.Controller.Entities; |
| | | 7 | | using MediaBrowser.Controller.Entities.Audio; |
| | | 8 | | using MediaBrowser.Controller.Entities.Movies; |
| | | 9 | | using MediaBrowser.Controller.Entities.TV; |
| | | 10 | | using MediaBrowser.Controller.Providers; |
| | | 11 | | using MediaBrowser.Model.Entities; |
| | | 12 | | using MediaBrowser.Model.IO; |
| | | 13 | | |
| | | 14 | | namespace Emby.Server.Implementations.Collections |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// A collection image provider. |
| | | 18 | | /// </summary> |
| | | 19 | | public class CollectionImageProvider : BaseDynamicImageProvider<BoxSet> |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="CollectionImageProvider"/> class. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="fileSystem">The filesystem.</param> |
| | | 25 | | /// <param name="providerManager">The provider manager.</param> |
| | | 26 | | /// <param name="applicationPaths">The application paths.</param> |
| | | 27 | | /// <param name="imageProcessor">The image processor.</param> |
| | | 28 | | public CollectionImageProvider( |
| | | 29 | | IFileSystem fileSystem, |
| | | 30 | | IProviderManager providerManager, |
| | | 31 | | IApplicationPaths applicationPaths, |
| | | 32 | | IImageProcessor imageProcessor) |
| | 21 | 33 | | : base(fileSystem, providerManager, applicationPaths, imageProcessor) |
| | | 34 | | { |
| | 21 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <inheritdoc /> |
| | | 38 | | protected override bool Supports(BaseItem item) |
| | | 39 | | { |
| | | 40 | | // Right now this is the only way to prevent this image from getting created ahead of internet image provide |
| | 0 | 41 | | if (!item.IsLocked) |
| | | 42 | | { |
| | 0 | 43 | | return false; |
| | | 44 | | } |
| | | 45 | | |
| | 0 | 46 | | return base.Supports(item); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <inheritdoc /> |
| | | 50 | | protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item) |
| | | 51 | | { |
| | 0 | 52 | | var playlist = (BoxSet)item; |
| | | 53 | | |
| | 0 | 54 | | return playlist.Children.Concat(playlist.GetLinkedChildren()) |
| | 0 | 55 | | .Select(i => |
| | 0 | 56 | | { |
| | 0 | 57 | | var subItem = i; |
| | 0 | 58 | | |
| | 0 | 59 | | var episode = subItem as Episode; |
| | 0 | 60 | | |
| | 0 | 61 | | var series = episode?.Series; |
| | 0 | 62 | | if (series is not null && series.HasImage(ImageType.Primary)) |
| | 0 | 63 | | { |
| | 0 | 64 | | return series; |
| | 0 | 65 | | } |
| | 0 | 66 | | |
| | 0 | 67 | | if (subItem.HasImage(ImageType.Primary)) |
| | 0 | 68 | | { |
| | 0 | 69 | | return subItem; |
| | 0 | 70 | | } |
| | 0 | 71 | | |
| | 0 | 72 | | var parent = subItem.GetOwner() ?? subItem.GetParent(); |
| | 0 | 73 | | |
| | 0 | 74 | | if (parent is not null && parent.HasImage(ImageType.Primary)) |
| | 0 | 75 | | { |
| | 0 | 76 | | if (parent is MusicAlbum) |
| | 0 | 77 | | { |
| | 0 | 78 | | return parent; |
| | 0 | 79 | | } |
| | 0 | 80 | | } |
| | 0 | 81 | | |
| | 0 | 82 | | return null; |
| | 0 | 83 | | }) |
| | 0 | 84 | | .Where(i => i is not null) |
| | 0 | 85 | | .GroupBy(x => x!.Id) // We removed the null values |
| | 0 | 86 | | .Select(x => x.First()) |
| | 0 | 87 | | .ToList()!; // Again... the list doesn't contain any null values |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <inheritdoc /> |
| | | 91 | | protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outpu |
| | | 92 | | { |
| | 0 | 93 | | return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary); |
| | | 94 | | } |
| | | 95 | | } |
| | | 96 | | } |