| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.IO; |
| | 7 | | using System.Linq; |
| | 8 | | using Jellyfin.Data.Enums; |
| | 9 | | using MediaBrowser.Controller; |
| | 10 | | using MediaBrowser.Controller.Entities; |
| | 11 | | using MediaBrowser.Controller.Library; |
| | 12 | | using MediaBrowser.Controller.Resolvers; |
| | 13 | | using MediaBrowser.Model.IO; |
| | 14 | |
|
| | 15 | | namespace Emby.Server.Implementations.Library.Resolvers |
| | 16 | | { |
| | 17 | | public class SpecialFolderResolver : GenericFolderResolver<Folder> |
| | 18 | | { |
| | 19 | | private readonly IFileSystem _fileSystem; |
| | 20 | | private readonly IServerApplicationPaths _appPaths; |
| | 21 | |
|
| 21 | 22 | | public SpecialFolderResolver(IFileSystem fileSystem, IServerApplicationPaths appPaths) |
| | 23 | | { |
| 21 | 24 | | _fileSystem = fileSystem; |
| 21 | 25 | | _appPaths = appPaths; |
| 21 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets the priority. |
| | 30 | | /// </summary> |
| | 31 | | /// <value>The priority.</value> |
| 21 | 32 | | public override ResolverPriority Priority => ResolverPriority.First; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Resolves the specified args. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="args">The args.</param> |
| | 38 | | /// <returns>Folder.</returns> |
| | 39 | | protected override Folder Resolve(ItemResolveArgs args) |
| | 40 | | { |
| 54 | 41 | | if (args.IsDirectory) |
| | 42 | | { |
| 47 | 43 | | if (args.IsPhysicalRoot) |
| | 44 | | { |
| 21 | 45 | | return new AggregateFolder(); |
| | 46 | | } |
| | 47 | |
|
| 26 | 48 | | if (string.Equals(args.Path, _appPaths.DefaultUserViewsPath, StringComparison.OrdinalIgnoreCase)) |
| | 49 | | { |
| 21 | 50 | | return new UserRootFolder(); // if we got here and still a root - must be user root |
| | 51 | | } |
| | 52 | |
|
| 5 | 53 | | if (args.IsVf) |
| | 54 | | { |
| 5 | 55 | | return new CollectionFolder |
| 5 | 56 | | { |
| 5 | 57 | | CollectionType = GetCollectionType(args), |
| 5 | 58 | | PhysicalLocationsList = args.PhysicalLocations |
| 5 | 59 | | }; |
| | 60 | | } |
| | 61 | | } |
| | 62 | |
|
| 7 | 63 | | return null; |
| | 64 | | } |
| | 65 | |
|
| | 66 | | private CollectionType? GetCollectionType(ItemResolveArgs args) |
| | 67 | | { |
| 5 | 68 | | return args.FileSystemChildren |
| 5 | 69 | | .Where(i => |
| 5 | 70 | | { |
| 5 | 71 | | try |
| 5 | 72 | | { |
| 5 | 73 | | return !i.IsDirectory && |
| 5 | 74 | | string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase); |
| 5 | 75 | | } |
| 5 | 76 | | catch (IOException) |
| 5 | 77 | | { |
| 5 | 78 | | return false; |
| 5 | 79 | | } |
| 5 | 80 | | }) |
| 5 | 81 | | .Select(i => _fileSystem.GetFileNameWithoutExtension(i)) |
| 5 | 82 | | .Select(i => Enum.TryParse<CollectionType>(i, out var collectionType) ? collectionType : (CollectionType |
| 5 | 83 | | .FirstOrDefault(i => i is not null); |
| | 84 | | } |
| | 85 | | } |
| | 86 | | } |