| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.IO; |
| | | 4 | | using System.Linq; |
| | | 5 | | using Jellyfin.Extensions; |
| | | 6 | | using MediaBrowser.Controller.Entities; |
| | | 7 | | using MediaBrowser.Controller.Entities.TV; |
| | | 8 | | using MediaBrowser.Controller.Providers; |
| | | 9 | | using MediaBrowser.Model.Entities; |
| | | 10 | | using MediaBrowser.Model.IO; |
| | | 11 | | |
| | | 12 | | namespace MediaBrowser.LocalMetadata.Images |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Episode local image provider. |
| | | 16 | | /// </summary> |
| | | 17 | | public class EpisodeLocalImageProvider : ILocalImageProvider, IHasOrder |
| | | 18 | | { |
| | | 19 | | /// <inheritdoc /> |
| | 0 | 20 | | public string Name => "Local Images"; |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | 0 | 23 | | public int Order => 0; |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public bool Supports(BaseItem item) |
| | | 27 | | { |
| | 53 | 28 | | return item is Episode && item.SupportsLocalMetadata; |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <inheritdoc /> |
| | | 32 | | public IEnumerable<LocalImageInfo> GetImages(BaseItem item, IDirectoryService directoryService) |
| | | 33 | | { |
| | 0 | 34 | | var parentPath = Path.GetDirectoryName(item.Path); |
| | 0 | 35 | | if (parentPath is null) |
| | | 36 | | { |
| | 0 | 37 | | return Enumerable.Empty<LocalImageInfo>(); |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | var parentPathFiles = directoryService.GetFiles(parentPath); |
| | 0 | 41 | | var nameWithoutExtension = Path.GetFileNameWithoutExtension(item.Path.AsSpan()).ToString(); |
| | | 42 | | |
| | 0 | 43 | | var images = GetImageFilesFromFolder(nameWithoutExtension, parentPathFiles); |
| | | 44 | | |
| | 0 | 45 | | var metadataSubDir = directoryService.GetDirectories(parentPath).FirstOrDefault(d => d.Name.Equals("metadata |
| | 0 | 46 | | if (metadataSubDir is not null) |
| | | 47 | | { |
| | 0 | 48 | | var files = directoryService.GetFiles(metadataSubDir.FullName); |
| | 0 | 49 | | images.AddRange(GetImageFilesFromFolder(nameWithoutExtension, files)); |
| | | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | return images; |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | private List<LocalImageInfo> GetImageFilesFromFolder(ReadOnlySpan<char> filenameWithoutExtension, List<FileSyste |
| | | 56 | | { |
| | 0 | 57 | | var list = new List<LocalImageInfo>(1); |
| | 0 | 58 | | var thumbName = string.Concat(filenameWithoutExtension, "-thumb"); |
| | | 59 | | |
| | 0 | 60 | | foreach (var i in filePaths) |
| | | 61 | | { |
| | 0 | 62 | | if (i.IsDirectory) |
| | | 63 | | { |
| | | 64 | | continue; |
| | | 65 | | } |
| | | 66 | | |
| | 0 | 67 | | if (BaseItem.SupportedImageExtensions.Contains(i.Extension.AsSpan(), StringComparison.OrdinalIgnoreCase) |
| | | 68 | | { |
| | 0 | 69 | | var currentNameWithoutExtension = Path.GetFileNameWithoutExtension(i.FullName.AsSpan()); |
| | | 70 | | |
| | 0 | 71 | | if (filenameWithoutExtension.Equals(currentNameWithoutExtension, StringComparison.OrdinalIgnoreCase) |
| | | 72 | | { |
| | 0 | 73 | | list.Add(new LocalImageInfo { FileInfo = i, Type = ImageType.Primary }); |
| | | 74 | | } |
| | 0 | 75 | | else if (currentNameWithoutExtension.Equals(thumbName, StringComparison.OrdinalIgnoreCase)) |
| | | 76 | | { |
| | 0 | 77 | | list.Add(new LocalImageInfo { FileInfo = i, Type = ImageType.Primary }); |
| | | 78 | | } |
| | | 79 | | } |
| | | 80 | | } |
| | | 81 | | |
| | 0 | 82 | | return list; |
| | | 83 | | } |
| | | 84 | | } |
| | | 85 | | } |