SpecialFolderResolver.cs 2.5 KB

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