2021-05-20 19:28:18 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2019-01-13 19:21:32 +00:00
|
|
|
using System.Linq;
|
2020-09-27 02:33:59 +00:00
|
|
|
using System.Threading.Tasks;
|
2021-11-15 14:56:02 +00:00
|
|
|
using Emby.Naming.Common;
|
2019-01-13 19:21:32 +00:00
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-02-21 01:33:05 +00:00
|
|
|
using MediaBrowser.Controller.Library;
|
2023-03-07 04:00:55 +00:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 16:53:58 +00:00
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-07-27 18:24:48 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2019-01-13 19:21:32 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-11-03 06:37:52 +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>
|
2022-03-31 14:17:37 +00:00
|
|
|
/// The music artist resolver.
|
2013-02-23 07:57:11 +00:00
|
|
|
/// </summary>
|
2013-03-03 06:58:04 +00:00
|
|
|
public class MusicArtistResolver : ItemResolver<MusicArtist>
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2020-05-12 20:03:15 +00:00
|
|
|
private readonly ILogger<MusicAlbumResolver> _logger;
|
2023-03-07 04:00:55 +00:00
|
|
|
private readonly NamingOptions _namingOptions;
|
|
|
|
private readonly IDirectoryService _directoryService;
|
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>
|
2022-03-31 14:17:37 +00:00
|
|
|
/// <param name="logger">Instance of the <see cref="MusicAlbumResolver"/> interface.</param>
|
|
|
|
/// <param name="namingOptions">The <see cref="NamingOptions"/>.</param>
|
2023-03-07 04:00:55 +00:00
|
|
|
/// <param name="directoryService">The directory service.</param>
|
2020-03-03 22:07:10 +00:00
|
|
|
public MusicArtistResolver(
|
2020-05-12 20:03:15 +00:00
|
|
|
ILogger<MusicAlbumResolver> logger,
|
2023-03-07 04:00:55 +00:00
|
|
|
NamingOptions namingOptions,
|
|
|
|
IDirectoryService directoryService)
|
2014-07-26 17:30:15 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
2021-11-15 14:56:02 +00:00
|
|
|
_namingOptions = namingOptions;
|
2023-03-07 04:00:55 +00:00
|
|
|
_directoryService = directoryService;
|
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>
|
2019-01-06 20:50:43 +00:00
|
|
|
public override ResolverPriority Priority => ResolverPriority.Second;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2013-02-23 07:57:11 +00:00
|
|
|
/// <summary>
|
2022-03-31 14:17:37 +00:00
|
|
|
/// Resolves the specified resolver arguments.
|
2013-02-23 07:57:11 +00:00
|
|
|
/// </summary>
|
2022-03-31 14:17:37 +00:00
|
|
|
/// <param name="args">The resolver arguments.</param>
|
|
|
|
/// <returns>A <see cref="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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-03-29 18:31:59 +00:00
|
|
|
// If there's a collection type and it's not music, it can't be a music artist
|
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
|
|
|
|
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
|
|
|
// 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
|
|
|
|
2023-03-07 04:00:55 +00:00
|
|
|
var albumResolver = new MusicAlbumResolver(_logger, _namingOptions, _directoryService);
|
2015-01-10 05:53:35 +00:00
|
|
|
|
2020-09-27 02:33:59 +00:00
|
|
|
var directories = args.FileSystemChildren.Where(i => i.IsDirectory);
|
|
|
|
|
|
|
|
var result = Parallel.ForEach(directories, (fileSystemInfo, state) =>
|
|
|
|
{
|
2022-03-31 14:17:37 +00:00
|
|
|
// If we contain a artist subfolder assume we are an artist folder
|
2022-03-29 18:31:59 +00:00
|
|
|
foreach (var subfolder in _namingOptions.ArtistSubfolders)
|
|
|
|
{
|
|
|
|
if (fileSystemInfo.Name.Equals(subfolder, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2022-03-31 14:17:37 +00:00
|
|
|
// Stop once we see an artist subfolder
|
2022-03-29 18:31:59 +00:00
|
|
|
state.Stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 14:17:37 +00:00
|
|
|
// If we contain a music album assume we are an artist folder
|
2023-03-07 04:00:55 +00:00
|
|
|
if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, _directoryService))
|
2020-09-27 02:33:59 +00:00
|
|
|
{
|
2022-03-31 14:17:37 +00:00
|
|
|
// Stop once we see a music album
|
2020-09-27 02:33:59 +00:00
|
|
|
state.Stop();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return !result.IsCompleted ? new MusicArtist() : null;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|