2013-04-28 00:44:38 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class AudioResolver
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AudioResolver : ItemResolver<Controller.Entities.Audio.Audio>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return ResolverPriority.Last; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
/// <returns>Entities.Audio.Audio.</returns>
|
|
|
|
|
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)
|
|
|
|
|
{
|
2013-04-28 00:44:38 +00:00
|
|
|
|
if (IsAudioFile(args.Path))
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
|
|
|
|
return new Controller.Entities.Audio.Audio();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The audio file extensions
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly string[] AudioFileExtensions = new[] {
|
|
|
|
|
".mp3",
|
|
|
|
|
".flac",
|
|
|
|
|
".wma",
|
|
|
|
|
".aac",
|
|
|
|
|
".acc",
|
|
|
|
|
".m4a",
|
|
|
|
|
".m4b",
|
|
|
|
|
".wav",
|
|
|
|
|
".ape",
|
|
|
|
|
".ogg",
|
|
|
|
|
".oga"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether [is audio file] [the specified args].
|
|
|
|
|
/// </summary>
|
2013-04-28 00:44:38 +00:00
|
|
|
|
/// <param name="path">The path.</param>
|
2013-03-03 06:58:04 +00:00
|
|
|
|
/// <returns><c>true</c> if [is audio file] [the specified args]; otherwise, <c>false</c>.</returns>
|
2013-04-28 00:44:38 +00:00
|
|
|
|
public static bool IsAudioFile(string path)
|
2013-03-03 06:58:04 +00:00
|
|
|
|
{
|
2013-04-28 00:44:38 +00:00
|
|
|
|
return AudioFileExtensions.Contains(Path.GetExtension(path), StringComparer.OrdinalIgnoreCase);
|
2013-03-03 06:58:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|