2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-03-03 09:53:58 -07:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-07-27 11:24:48 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2013-04-28 09:25:14 -07:00
|
|
|
|
using System.IO;
|
2013-04-27 17:44:38 -07:00
|
|
|
|
using System.Linq;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-02 23:58:04 -07:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-23 00:57:11 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MusicArtistResolver
|
|
|
|
|
/// </summary>
|
2013-03-02 23:58:04 -07:00
|
|
|
|
public class MusicArtistResolver : ItemResolver<MusicArtist>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-07-27 11:24:48 -07:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
|
|
|
|
|
public MusicArtistResolver(ILibraryManager libraryManager)
|
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 00:57:11 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get { return ResolverPriority.Third; } // we need to be ahead of the generic folder resolver but behind the movie one
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 00:57:11 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
/// <returns>MusicArtist.</returns>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
protected override MusicArtist Resolve(ItemResolveArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.IsDirectory) return null;
|
|
|
|
|
|
|
|
|
|
//Avoid mis-identifying top folders
|
|
|
|
|
if (args.Parent == null) return null;
|
|
|
|
|
if (args.Parent.IsRoot) return null;
|
|
|
|
|
|
2013-06-02 05:43:53 -07:00
|
|
|
|
// Don't allow nested artists
|
|
|
|
|
if (args.Parent is MusicArtist)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-27 11:24:48 -07:00
|
|
|
|
var collectionType = args.Parent == null ? null : _libraryManager.FindCollectionType(args.Parent);
|
|
|
|
|
|
|
|
|
|
// If there's a collection type and it's not music, it can't be a series
|
|
|
|
|
if (!string.IsNullOrEmpty(collectionType) &&
|
|
|
|
|
!string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// If we contain an album assume we are an artist folder
|
2013-06-11 13:35:54 -07:00
|
|
|
|
return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName)) ? new MusicArtist() : null;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|