AudioResolver.cs 2.5 KB

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