| | | 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 | | { |
| | 59 | 41 | | if (args.IsDirectory) |
| | | 42 | | { |
| | 49 | 43 | | if (args.IsPhysicalRoot) |
| | | 44 | | { |
| | 21 | 45 | | return new AggregateFolder(); |
| | | 46 | | } |
| | | 47 | | |
| | 28 | 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 | | |
| | 7 | 53 | | if (args.IsVf) |
| | | 54 | | { |
| | 7 | 55 | | return new CollectionFolder |
| | 7 | 56 | | { |
| | 7 | 57 | | CollectionType = GetCollectionType(args), |
| | 7 | 58 | | PhysicalLocationsList = args.PhysicalLocations |
| | 7 | 59 | | }; |
| | | 60 | | } |
| | | 61 | | } |
| | | 62 | | |
| | 10 | 63 | | return null; |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | private CollectionType? GetCollectionType(ItemResolveArgs args) |
| | | 67 | | { |
| | 7 | 68 | | return args.FileSystemChildren |
| | 7 | 69 | | .Where(i => |
| | 7 | 70 | | { |
| | 7 | 71 | | try |
| | 7 | 72 | | { |
| | 7 | 73 | | return !i.IsDirectory && |
| | 7 | 74 | | string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase); |
| | 7 | 75 | | } |
| | 7 | 76 | | catch (IOException) |
| | 7 | 77 | | { |
| | 7 | 78 | | return false; |
| | 7 | 79 | | } |
| | 7 | 80 | | }) |
| | 7 | 81 | | .Select(i => _fileSystem.GetFileNameWithoutExtension(i)) |
| | 7 | 82 | | .Select(i => Enum.TryParse<CollectionType>(i, out var collectionType) ? collectionType : (CollectionType |
| | 7 | 83 | | .FirstOrDefault(i => i is not null); |
| | | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |