2013-04-27 17:44:38 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2014-02-23 13:35:58 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2016-12-11 22:49:19 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-03-02 23:58:04 -07:00
|
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class AudioResolver
|
|
|
|
|
/// </summary>
|
2016-11-02 23:37:52 -07:00
|
|
|
|
public class AudioResolver : ItemResolver<MediaBrowser.Controller.Entities.Audio.Audio>
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
2014-11-16 13:44:08 -07:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
|
|
|
|
|
public AudioResolver(ILibraryManager libraryManager)
|
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-02 23:58:04 -07:00
|
|
|
|
/// <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>
|
2016-11-02 23:37:52 -07:00
|
|
|
|
protected override MediaBrowser.Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args)
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
|
|
|
|
// Return audio if the path is a file and has a matching extension
|
|
|
|
|
|
|
|
|
|
if (!args.IsDirectory)
|
|
|
|
|
{
|
2016-08-12 22:49:00 -07:00
|
|
|
|
var libraryOptions = args.GetLibraryOptions();
|
|
|
|
|
|
|
|
|
|
if (_libraryManager.IsAudioFile(args.Path, libraryOptions))
|
2013-03-02 23:58:04 -07:00
|
|
|
|
{
|
2014-02-23 13:35:58 -07:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
|
|
2014-12-10 23:20:28 -07:00
|
|
|
|
var isMixed = string.IsNullOrWhiteSpace(collectionType);
|
|
|
|
|
|
|
|
|
|
// For conflicting extensions, give priority to videos
|
2016-08-12 22:49:00 -07:00
|
|
|
|
if (isMixed && _libraryManager.IsVideoFile(args.Path, libraryOptions))
|
2014-12-10 23:20:28 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 20:54:52 -07:00
|
|
|
|
var isStandalone = args.Parent == null;
|
|
|
|
|
|
|
|
|
|
if (isStandalone ||
|
2014-12-10 23:20:28 -07:00
|
|
|
|
string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
isMixed)
|
2014-02-23 13:35:58 -07:00
|
|
|
|
{
|
2016-11-02 23:37:52 -07:00
|
|
|
|
return new MediaBrowser.Controller.Entities.Audio.Audio();
|
2014-02-23 13:35:58 -07:00
|
|
|
|
}
|
2016-12-11 22:49:19 -07:00
|
|
|
|
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new AudioBook();
|
|
|
|
|
}
|
2013-03-02 23:58:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|