2014-07-26 17:30:15 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-09-18 02:43:34 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-03-03 16:53:58 +00:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-07-27 18:24:48 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-26 17:30:15 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-07-27 18:24:48 +00:00
|
|
|
|
using System;
|
2013-04-28 16:25:14 +00:00
|
|
|
|
using System.IO;
|
2013-04-28 00:44:38 +00:00
|
|
|
|
using System.Linq;
|
2015-10-04 04:23:11 +00:00
|
|
|
|
using CommonIO;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-03 06:58:04 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-23 07:57:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MusicArtistResolver
|
|
|
|
|
/// </summary>
|
2013-03-03 06:58:04 +00:00
|
|
|
|
public class MusicArtistResolver : ItemResolver<MusicArtist>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-07-26 17:30:15 +00:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-11-16 20:44:08 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-07-26 17:30:15 +00:00
|
|
|
|
|
2014-11-16 20:44:08 +00:00
|
|
|
|
public MusicArtistResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager)
|
2014-07-26 17:30:15 +00:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_fileSystem = fileSystem;
|
2014-11-16 20:44:08 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2014-07-26 17:30:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 07:57:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
2014-12-20 06:06:27 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Behind special folder resolver
|
|
|
|
|
return ResolverPriority.Second;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 07:57:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
/// <returns>MusicArtist.</returns>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
protected override MusicArtist Resolve(ItemResolveArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.IsDirectory) return null;
|
|
|
|
|
|
2014-12-20 06:06:27 +00:00
|
|
|
|
// Avoid mis-identifying top folders
|
2013-02-21 01:33:05 +00:00
|
|
|
|
if (args.Parent.IsRoot) return null;
|
|
|
|
|
|
2013-06-02 12:43:53 +00:00
|
|
|
|
// Don't allow nested artists
|
2014-12-15 05:16:23 +00:00
|
|
|
|
if (args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>())
|
2013-06-02 12:43:53 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:07:35 +00:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
2013-07-27 18:24:48 +00:00
|
|
|
|
|
2014-12-20 06:06:27 +00:00
|
|
|
|
var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);
|
2014-07-30 03:31:35 +00:00
|
|
|
|
|
2013-07-27 18:24:48 +00:00
|
|
|
|
// If there's a collection type and it's not music, it can't be a series
|
2014-07-30 03:31:35 +00:00
|
|
|
|
if (!isMusicMediaFolder)
|
2013-07-27 18:24:48 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-02-13 05:11:54 +00:00
|
|
|
|
|
|
|
|
|
var directoryService = args.DirectoryService;
|
2015-01-10 05:53:35 +00:00
|
|
|
|
|
|
|
|
|
var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
// If we contain an album assume we are an artist folder
|
2015-01-10 05:53:35 +00:00
|
|
|
|
return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService)) ? new MusicArtist() : null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|