jellyfin/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs

95 lines
3.0 KiB
C#
Raw Normal View History

2016-03-27 14:11:27 -07:00
using MediaBrowser.Controller.Entities.Audio;
2013-02-20 18:33:05 -07:00
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
2014-07-26 10:30:15 -07:00
using MediaBrowser.Model.Logging;
using System;
2013-04-28 09:25:14 -07:00
using System.IO;
using System.Linq;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
2016-10-07 08:08:13 -07:00
using MediaBrowser.Controller.Configuration;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Controller.IO;
2013-02-20 18:33:05 -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>
public class MusicArtistResolver : ItemResolver<MusicArtist>
2013-02-20 18:33:05 -07:00
{
2014-07-26 10:30:15 -07:00
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
2014-11-16 13:44:08 -07:00
private readonly ILibraryManager _libraryManager;
2016-10-07 08:08:13 -07:00
private readonly IServerConfigurationManager _config;
2014-07-26 10:30:15 -07:00
2016-10-07 08:08:13 -07:00
public MusicArtistResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager, IServerConfigurationManager config)
2014-07-26 10:30:15 -07:00
{
_logger = logger;
_fileSystem = fileSystem;
2014-11-16 13:44:08 -07:00
_libraryManager = libraryManager;
2016-10-07 08:08:13 -07:00
_config = config;
2014-07-26 10:30:15 -07:00
}
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
{
2014-12-19 23:06:27 -07:00
get
{
// Behind special folder resolver
return ResolverPriority.Second;
}
2013-02-20 18:33:05 -07:00
}
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;
2013-06-02 05:43:53 -07:00
// Don't allow nested artists
2014-12-14 22:16:23 -07:00
if (args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>())
2013-06-02 05:43:53 -07:00
{
return null;
}
var collectionType = args.GetCollectionType();
2014-12-19 23:06:27 -07:00
var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);
2014-07-29 20:31:35 -07:00
// If there's a collection type and it's not music, it can't be a series
2014-07-29 20:31:35 -07:00
if (!isMusicMediaFolder)
{
return null;
}
2014-02-12 22:11:54 -07:00
2016-10-09 00:18:43 -07:00
if (args.ContainsFileSystemEntryByName("artist.nfo"))
2016-10-07 08:08:13 -07:00
{
2016-10-09 00:18:43 -07:00
return new MusicArtist();
2016-10-07 08:08:13 -07:00
}
if (_config.Configuration.EnableSimpleArtistDetection)
{
return null;
}
2016-10-09 00:18:43 -07:00
// Avoid mis-identifying top folders
if (args.Parent.IsRoot) return null;
2014-02-12 22:11:54 -07:00
var directoryService = args.DirectoryService;
2015-01-09 22:53:35 -07:00
var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);
2013-02-20 18:33:05 -07:00
// If we contain an album assume we are an artist folder
2016-10-25 12:02:04 -07:00
return args.FileSystemChildren.Where(i => i.IsDirectory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService, args.GetLibraryOptions())) ? new MusicArtist() : null;
2013-02-20 18:33:05 -07:00
}
}
}