using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using System;
using System.IO;
using System.Linq;
using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{
///
/// Class AudioResolver
///
public class AudioResolver : ItemResolver
{
///
/// Gets the priority.
///
/// The priority.
public override ResolverPriority Priority
{
get { return ResolverPriority.Last; }
}
///
/// Resolves the specified args.
///
/// The args.
/// Entities.Audio.Audio.
protected override Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
{
// Return audio if the path is a file and has a matching extension
if (!args.IsDirectory)
{
if (IsAudioFile(args))
{
return new Controller.Entities.Audio.Audio();
}
}
return null;
}
///
/// The audio file extensions
///
public static readonly string[] AudioFileExtensions = new[] {
".mp3",
".flac",
".wma",
".aac",
".acc",
".m4a",
".m4b",
".wav",
".ape",
".ogg",
".oga"
};
///
/// Determines whether [is audio file] [the specified args].
///
/// The args.
/// true if [is audio file] [the specified args]; otherwise, false.
public static bool IsAudioFile(ItemResolveArgs args)
{
return AudioFileExtensions.Contains(Path.GetExtension(args.Path), StringComparer.OrdinalIgnoreCase);
}
///
/// Determines whether [is audio file] [the specified file].
///
/// The file.
/// true if [is audio file] [the specified file]; otherwise, false.
public static bool IsAudioFile(WIN32_FIND_DATA file)
{
return AudioFileExtensions.Contains(Path.GetExtension(file.Path), StringComparer.OrdinalIgnoreCase);
}
}
}