2012-07-26 04:33:11 +02:00
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
|
using System.IO;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Resolvers
|
|
|
|
|
{
|
2012-07-26 04:33:11 +02:00
|
|
|
|
[Export(typeof(IBaseItemResolver))]
|
2012-07-12 08:55:27 +02:00
|
|
|
|
public class AudioResolver : BaseItemResolver<Audio>
|
|
|
|
|
{
|
|
|
|
|
protected override Audio Resolve(ItemResolveEventArgs args)
|
|
|
|
|
{
|
2012-07-20 04:22:44 +02:00
|
|
|
|
// Return audio if the path is a file and has a matching extension
|
|
|
|
|
|
2012-07-12 08:55:27 +02:00
|
|
|
|
if (!args.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
if (IsAudioFile(args.Path))
|
|
|
|
|
{
|
|
|
|
|
return new Audio();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-06 15:20:24 +02:00
|
|
|
|
public static bool IsAudioFile(string path)
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
|
|
|
|
string extension = Path.GetExtension(path).ToLower();
|
|
|
|
|
|
|
|
|
|
switch (extension)
|
|
|
|
|
{
|
|
|
|
|
case ".mp3":
|
|
|
|
|
case ".wma":
|
|
|
|
|
case ".acc":
|
|
|
|
|
case ".flac":
|
|
|
|
|
case ".m4a":
|
|
|
|
|
case ".m4b":
|
|
|
|
|
case ".wav":
|
|
|
|
|
case ".ape":
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|