MusicArtistResolver.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using MediaBrowser.Controller.Entities.Audio;
  2. using MediaBrowser.Controller.Entities.Movies;
  3. using MediaBrowser.Controller.Entities.TV;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.Resolvers;
  6. using MediaBrowser.Model.Entities;
  7. using System;
  8. using System.IO;
  9. using System.Linq;
  10. namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
  11. {
  12. /// <summary>
  13. /// Class MusicArtistResolver
  14. /// </summary>
  15. public class MusicArtistResolver : ItemResolver<MusicArtist>
  16. {
  17. /// <summary>
  18. /// Gets the priority.
  19. /// </summary>
  20. /// <value>The priority.</value>
  21. public override ResolverPriority Priority
  22. {
  23. get { return ResolverPriority.Third; } // we need to be ahead of the generic folder resolver but behind the movie one
  24. }
  25. /// <summary>
  26. /// Resolves the specified args.
  27. /// </summary>
  28. /// <param name="args">The args.</param>
  29. /// <returns>MusicArtist.</returns>
  30. protected override MusicArtist Resolve(ItemResolveArgs args)
  31. {
  32. if (!args.IsDirectory) return null;
  33. //Avoid mis-identifying top folders
  34. if (args.Parent == null) return null;
  35. if (args.Parent.IsRoot) return null;
  36. // Don't allow nested artists
  37. if (args.Parent is MusicArtist)
  38. {
  39. return null;
  40. }
  41. // Optimization
  42. if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season)
  43. {
  44. return null;
  45. }
  46. var collectionType = args.GetCollectionType();
  47. // If there's a collection type and it's not music, it can't be a series
  48. if (!string.IsNullOrEmpty(collectionType) &&
  49. !string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
  50. {
  51. return null;
  52. }
  53. var directoryService = args.DirectoryService;
  54. // If we contain an album assume we are an artist folder
  55. return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, directoryService)) ? new MusicArtist() : null;
  56. }
  57. }
  58. }