MusicArtistResolver.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using MediaBrowser.Controller.Entities.Audio;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Controller.Resolvers;
  4. using MediaBrowser.Model.Entities;
  5. using Microsoft.Extensions.Logging;
  6. using System;
  7. using System.IO;
  8. using System.Linq;
  9. using MediaBrowser.Model.IO;
  10. using MediaBrowser.Controller.Configuration;
  11. using MediaBrowser.Controller.IO;
  12. namespace Emby.Server.Implementations.Library.Resolvers.Audio
  13. {
  14. /// <summary>
  15. /// Class MusicArtistResolver
  16. /// </summary>
  17. public class MusicArtistResolver : ItemResolver<MusicArtist>
  18. {
  19. private readonly ILogger _logger;
  20. private readonly IFileSystem _fileSystem;
  21. private readonly ILibraryManager _libraryManager;
  22. private readonly IServerConfigurationManager _config;
  23. public MusicArtistResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager, IServerConfigurationManager config)
  24. {
  25. _logger = logger;
  26. _fileSystem = fileSystem;
  27. _libraryManager = libraryManager;
  28. _config = config;
  29. }
  30. /// <summary>
  31. /// Gets the priority.
  32. /// </summary>
  33. /// <value>The priority.</value>
  34. public override ResolverPriority Priority => ResolverPriority.Second;
  35. /// <summary>
  36. /// Resolves the specified args.
  37. /// </summary>
  38. /// <param name="args">The args.</param>
  39. /// <returns>MusicArtist.</returns>
  40. protected override MusicArtist Resolve(ItemResolveArgs args)
  41. {
  42. if (!args.IsDirectory) return null;
  43. // Don't allow nested artists
  44. if (args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>())
  45. {
  46. return null;
  47. }
  48. var collectionType = args.GetCollectionType();
  49. var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);
  50. // If there's a collection type and it's not music, it can't be a series
  51. if (!isMusicMediaFolder)
  52. {
  53. return null;
  54. }
  55. if (args.ContainsFileSystemEntryByName("artist.nfo"))
  56. {
  57. return new MusicArtist();
  58. }
  59. if (_config.Configuration.EnableSimpleArtistDetection)
  60. {
  61. return null;
  62. }
  63. // Avoid mis-identifying top folders
  64. if (args.Parent.IsRoot) return null;
  65. var directoryService = args.DirectoryService;
  66. var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);
  67. // If we contain an album assume we are an artist folder
  68. return args.FileSystemChildren.Where(i => i.IsDirectory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService, args.GetLibraryOptions())) ? new MusicArtist() : null;
  69. }
  70. }
  71. }