AudioResolver.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using MediaBrowser.Controller.IO;
  2. using MediaBrowser.Controller.Library;
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using MediaBrowser.Controller.Resolvers;
  7. namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
  8. {
  9. /// <summary>
  10. /// Class AudioResolver
  11. /// </summary>
  12. public class AudioResolver : ItemResolver<Controller.Entities.Audio.Audio>
  13. {
  14. /// <summary>
  15. /// Gets the priority.
  16. /// </summary>
  17. /// <value>The priority.</value>
  18. public override ResolverPriority Priority
  19. {
  20. get { return ResolverPriority.Last; }
  21. }
  22. /// <summary>
  23. /// Resolves the specified args.
  24. /// </summary>
  25. /// <param name="args">The args.</param>
  26. /// <returns>Entities.Audio.Audio.</returns>
  27. protected override Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
  28. {
  29. // Return audio if the path is a file and has a matching extension
  30. if (!args.IsDirectory)
  31. {
  32. if (IsAudioFile(args))
  33. {
  34. return new Controller.Entities.Audio.Audio();
  35. }
  36. }
  37. return null;
  38. }
  39. /// <summary>
  40. /// The audio file extensions
  41. /// </summary>
  42. public static readonly string[] AudioFileExtensions = new[] {
  43. ".mp3",
  44. ".flac",
  45. ".wma",
  46. ".aac",
  47. ".acc",
  48. ".m4a",
  49. ".m4b",
  50. ".wav",
  51. ".ape",
  52. ".ogg",
  53. ".oga"
  54. };
  55. /// <summary>
  56. /// Determines whether [is audio file] [the specified args].
  57. /// </summary>
  58. /// <param name="args">The args.</param>
  59. /// <returns><c>true</c> if [is audio file] [the specified args]; otherwise, <c>false</c>.</returns>
  60. public static bool IsAudioFile(ItemResolveArgs args)
  61. {
  62. return AudioFileExtensions.Contains(Path.GetExtension(args.Path), StringComparer.OrdinalIgnoreCase);
  63. }
  64. /// <summary>
  65. /// Determines whether [is audio file] [the specified file].
  66. /// </summary>
  67. /// <param name="file">The file.</param>
  68. /// <returns><c>true</c> if [is audio file] [the specified file]; otherwise, <c>false</c>.</returns>
  69. public static bool IsAudioFile(WIN32_FIND_DATA file)
  70. {
  71. return AudioFileExtensions.Contains(Path.GetExtension(file.Path), StringComparer.OrdinalIgnoreCase);
  72. }
  73. }
  74. }