jellyfin-server/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs

97 lines
3.2 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.Audio;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
2013-02-21 01:33:05 +00:00
namespace Emby.Server.Implementations.Library.Resolvers.Audio
2013-02-21 01:33:05 +00:00
{
2013-02-23 07:57:11 +00:00
/// <summary>
2019-11-01 17:38:54 +00:00
/// Class MusicArtistResolver.
2013-02-23 07:57:11 +00:00
/// </summary>
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;
2016-10-07 15:08:13 +00:00
private readonly IServerConfigurationManager _config;
2014-07-26 17:30:15 +00:00
2019-11-01 17:38:54 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="MusicArtistResolver"/> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="config">The configuration manager.</param>
2016-10-07 15:08:13 +00:00
public MusicArtistResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager, IServerConfigurationManager config)
2014-07-26 17:30:15 +00:00
{
_logger = logger;
_fileSystem = fileSystem;
2014-11-16 20:44:08 +00:00
_libraryManager = libraryManager;
2016-10-07 15:08:13 +00:00
_config = config;
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>
public override ResolverPriority Priority => 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)
{
2019-11-01 17:38:54 +00:00
if (!args.IsDirectory)
{
return null;
}
2013-02-21 01:33:05 +00:00
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;
}
var collectionType = args.GetCollectionType();
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
// 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)
{
return null;
}
2014-02-13 05:11:54 +00:00
2016-10-09 07:18:43 +00:00
if (args.ContainsFileSystemEntryByName("artist.nfo"))
2016-10-07 15:08:13 +00:00
{
2016-10-09 07:18:43 +00:00
return new MusicArtist();
2016-10-07 15:08:13 +00:00
}
2017-02-08 18:50:33 +00:00
if (_config.Configuration.EnableSimpleArtistDetection)
{
return null;
}
2016-10-07 15:08:13 +00:00
2017-02-08 18:50:33 +00:00
// Avoid mis-identifying top folders
2020-02-19 20:56:35 +00:00
if (args.Parent.IsRoot)
{
return null;
}
2016-10-09 07:18:43 +00:00
2017-02-08 18:50:33 +00:00
var directoryService = args.DirectoryService;
2015-01-10 05:53:35 +00:00
2017-02-08 18:50:33 +00:00
var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);
2015-01-10 05:53:35 +00:00
2017-02-08 18:50:33 +00:00
// If we contain an album assume we are an artist folder
2020-02-19 20:56:35 +00:00
return args.FileSystemChildren.Where(i => i.IsDirectory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService)) ? new MusicArtist() : null;
2013-02-21 01:33:05 +00:00
}
}
}