| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.IO; |
| | | 8 | | using System.Linq; |
| | | 9 | | using Jellyfin.Api.Extensions; |
| | | 10 | | using Jellyfin.Data.Enums; |
| | | 11 | | using Jellyfin.Database.Implementations.Enums; |
| | | 12 | | using MediaBrowser.Common.Configuration; |
| | | 13 | | using MediaBrowser.Controller.Drawing; |
| | | 14 | | using MediaBrowser.Controller.Dto; |
| | | 15 | | using MediaBrowser.Controller.Entities; |
| | | 16 | | using MediaBrowser.Controller.Library; |
| | | 17 | | using MediaBrowser.Controller.Providers; |
| | | 18 | | using MediaBrowser.Model.Entities; |
| | | 19 | | using MediaBrowser.Model.IO; |
| | | 20 | | |
| | | 21 | | namespace Emby.Server.Implementations.Images |
| | | 22 | | { |
| | | 23 | | public class CollectionFolderImageProvider : BaseDynamicImageProvider<CollectionFolder> |
| | | 24 | | { |
| | | 25 | | private readonly ILibraryManager _libraryManager; |
| | | 26 | | |
| | 28 | 27 | | public CollectionFolderImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths |
| | | 28 | | { |
| | 28 | 29 | | _libraryManager = libraryManager; |
| | 28 | 30 | | } |
| | | 31 | | |
| | | 32 | | protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item) |
| | | 33 | | { |
| | 45 | 34 | | var view = (CollectionFolder)item; |
| | 45 | 35 | | var viewType = view.CollectionType; |
| | 45 | 36 | | var includeItemTypes = DtoExtensions.GetBaseItemKindsForCollectionType(viewType); |
| | 45 | 37 | | var recursive = viewType != CollectionType.playlists; |
| | | 38 | | |
| | 45 | 39 | | if (viewType == CollectionType.music) |
| | | 40 | | { |
| | | 41 | | // Music albums usually don't have dedicated backdrops, so use artist instead. |
| | | 42 | | // Artists carry no library of their own, so an item query for them is not |
| | | 43 | | // restricted to this library and would collage the artists of every music |
| | | 44 | | // library. Resolve them through the tracks that credit them instead. |
| | 1 | 45 | | return GetArtistsWithImages(view); |
| | | 46 | | } |
| | | 47 | | |
| | 44 | 48 | | return view.GetItemList(new InternalItemsQuery |
| | 44 | 49 | | { |
| | 44 | 50 | | CollapseBoxSetItems = false, |
| | 44 | 51 | | Recursive = recursive, |
| | 44 | 52 | | DtoOptions = new DtoOptions(false), |
| | 44 | 53 | | ImageTypes = [ImageType.Primary], |
| | 44 | 54 | | Limit = 8, |
| | 44 | 55 | | OrderBy = [(ItemSortBy.Random, SortOrder.Ascending)], |
| | 44 | 56 | | IncludeItemTypes = includeItemTypes |
| | 44 | 57 | | }); |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | private IReadOnlyList<BaseItem> GetArtistsWithImages(CollectionFolder view) |
| | | 61 | | { |
| | 1 | 62 | | return _libraryManager.GetAllArtists(new InternalItemsQuery |
| | 1 | 63 | | { |
| | 1 | 64 | | AncestorIds = [view.Id], |
| | 1 | 65 | | DtoOptions = new DtoOptions(false), |
| | 1 | 66 | | EnableTotalRecordCount = false, |
| | 1 | 67 | | ImageTypes = [ImageType.Primary], |
| | 1 | 68 | | Limit = 8, |
| | 1 | 69 | | OrderBy = [(ItemSortBy.Random, SortOrder.Ascending)] |
| | 1 | 70 | | }).Items.Select(i => i.Item).ToArray(); |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | protected override bool Supports(BaseItem item) |
| | | 74 | | { |
| | 44 | 75 | | return item is CollectionFolder; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outpu |
| | | 79 | | { |
| | 7 | 80 | | var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png"); |
| | | 81 | | |
| | 7 | 82 | | if (imageType == ImageType.Primary) |
| | | 83 | | { |
| | 7 | 84 | | if (itemsWithImages.Count == 0) |
| | | 85 | | { |
| | 7 | 86 | | return null; |
| | | 87 | | } |
| | | 88 | | |
| | 0 | 89 | | return CreateThumbCollage(item, itemsWithImages, outputPath, 960, 540); |
| | | 90 | | } |
| | | 91 | | |
| | 0 | 92 | | return base.CreateImage(item, itemsWithImages, outputPath, imageType, imageIndex); |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | protected override bool HasChangedByDate(BaseItem item, ItemImageInfo image) |
| | | 96 | | { |
| | 0 | 97 | | var age = DateTime.UtcNow - image.DateModified; |
| | 0 | 98 | | return age.TotalDays > 7; |
| | | 99 | | } |
| | | 100 | | } |
| | | 101 | | } |