From 5fdd7ec6725a3acb3365e92c090f2e90bbbf122f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 16 Nov 2014 15:44:08 -0500 Subject: add new naming project --- .../Library/Resolvers/Audio/AudioResolver.cs | 12 +++- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 65 ++++++++++------------ .../Library/Resolvers/Audio/MusicArtistResolver.cs | 6 +- 3 files changed, 43 insertions(+), 40 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/Audio') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs index dec6908f9..62eb1f47d 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs @@ -10,6 +10,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio /// public class AudioResolver : ItemResolver { + private readonly ILibraryManager _libraryManager; + + public AudioResolver(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + /// /// Gets the priority. /// @@ -30,15 +37,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio if (!args.IsDirectory) { - if (EntityResolutionHelper.IsAudioFile(args.Path)) + if (_libraryManager.IsAudioFile(args.Path)) { var collectionType = args.GetCollectionType(); var isStandalone = args.Parent == null; if (isStandalone || - string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) || - string.IsNullOrEmpty(collectionType)) + string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) { return new Controller.Entities.Audio.Audio(); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 1f9dc56f9..a50059461 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -8,6 +8,7 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; +using MediaBrowser.Naming.Audio; using System; using System.Collections.Generic; using System.IO; @@ -21,11 +22,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { private readonly ILogger _logger; private readonly IFileSystem _fileSystem; + private readonly ILibraryManager _libraryManager; - public MusicAlbumResolver(ILogger logger, IFileSystem fileSystem) + public MusicAlbumResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager) { _logger = logger; _fileSystem = fileSystem; + _libraryManager = libraryManager; } /// @@ -68,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio return null; } - return IsMusicAlbum(args, isMusicMediaFolder) ? new MusicAlbum() : null; + return IsMusicAlbum(args) ? new MusicAlbum() : null; } @@ -76,29 +79,29 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio /// Determine if the supplied file data points to a music album /// /// The path. - /// if set to true [is music media folder]. /// The directory service. /// The logger. /// The file system. + /// The library manager. /// true if [is music album] [the specified data]; otherwise, false. - public static bool IsMusicAlbum(string path, bool isMusicMediaFolder, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem) + public static bool IsMusicAlbum(string path, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem, + ILibraryManager libraryManager) { - return ContainsMusic(directoryService.GetFileSystemEntries(path), isMusicMediaFolder, true, directoryService, logger, fileSystem); + return ContainsMusic(directoryService.GetFileSystemEntries(path), true, directoryService, logger, fileSystem, libraryManager); } /// /// Determine if the supplied resolve args should be considered a music album /// /// The args. - /// if set to true [is music media folder]. /// true if [is music album] [the specified args]; otherwise, false. - private bool IsMusicAlbum(ItemResolveArgs args, bool isMusicMediaFolder) + private bool IsMusicAlbum(ItemResolveArgs args) { // Args points to an album if parent is an Artist folder or it directly contains music if (args.IsDirectory) { //if (args.Parent is MusicArtist) return true; //saves us from testing children twice - if (ContainsMusic(args.FileSystemChildren, isMusicMediaFolder, true, args.DirectoryService, _logger, _fileSystem)) return true; + if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService, _logger, _fileSystem, _libraryManager)) return true; } return false; @@ -108,41 +111,34 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio /// Determine if the supplied list contains what we should consider music /// /// The list. - /// if set to true [is music media folder]. /// if set to true [allow subfolders]. /// The directory service. /// The logger. /// The file system. + /// The library manager. /// true if the specified list contains music; otherwise, false. private static bool ContainsMusic(IEnumerable list, - bool isMusicMediaFolder, bool allowSubfolders, IDirectoryService directoryService, ILogger logger, - IFileSystem fileSystem) + IFileSystem fileSystem, + ILibraryManager libraryManager) { - // If list contains at least 2 audio files or at least one and no video files consider it to contain music - var foundAudio = 0; - var discSubfolderCount = 0; foreach (var fileSystemInfo in list) { if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { - if (isMusicMediaFolder && allowSubfolders && IsAlbumSubfolder(fileSystemInfo, true, directoryService, logger, fileSystem)) + if (allowSubfolders && IsAlbumSubfolder(fileSystemInfo, directoryService, logger, fileSystem, libraryManager)) { discSubfolderCount++; } - if (!IsAdditionalSubfolderAllowed(fileSystemInfo)) - { - return false; - } } var fullName = fileSystemInfo.FullName; - if (EntityResolutionHelper.IsAudioFile(fullName)) + if (libraryManager.IsAudioFile(fullName)) { // Don't resolve these into audio files if (string.Equals(fileSystem.GetFileNameWithoutExtension(fullName), BaseItem.ThemeSongFilename)) @@ -150,22 +146,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio continue; } - foundAudio++; - } - else if (EntityResolutionHelper.IsVideoFile(fullName)) return false; - else if (EntityResolutionHelper.IsVideoPlaceHolder(fullName)) return false; - - if (foundAudio >= 2) - { return true; } } - // or a single audio file and no video files - return foundAudio > 0 || discSubfolderCount > 0; + return discSubfolderCount > 0; } - private static bool IsAlbumSubfolder(FileSystemInfo directory, bool isMusicMediaFolder, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem) + private static bool IsAlbumSubfolder(FileSystemInfo directory, IDirectoryService directoryService, ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager) { var path = directory.FullName; @@ -173,7 +161,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { logger.Debug("Found multi-disc folder: " + path); - return ContainsMusic(directoryService.GetFileSystemEntries(path), isMusicMediaFolder, false, directoryService, logger, fileSystem); + return ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager); } return false; @@ -181,13 +169,20 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio public static bool IsMultiDiscFolder(string path) { - return EntityResolutionHelper.IsMultiDiscAlbumFolder(path); + return IsMultiDiscAlbumFolder(path); } - private static bool IsAdditionalSubfolderAllowed(FileSystemInfo directory) + /// + /// Determines whether [is multi disc album folder] [the specified path]. + /// + /// The path. + /// true if [is multi disc album folder] [the specified path]; otherwise, false. + private static bool IsMultiDiscAlbumFolder(string path) { - // Resolver will ignore them based on rules engine - return true; + var parser = new AlbumParser(new AudioOptions(), new Naming.Logging.NullLogger()); + var result = parser.ParseMultiPart(path); + + return result.IsMultiPart; } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index 2417d5dcb..53063b35e 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -19,11 +19,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { private readonly ILogger _logger; private readonly IFileSystem _fileSystem; + private readonly ILibraryManager _libraryManager; - public MusicArtistResolver(ILogger logger, IFileSystem fileSystem) + public MusicArtistResolver(ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager) { _logger = logger; _fileSystem = fileSystem; + _libraryManager = libraryManager; } /// @@ -74,7 +76,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio var directoryService = args.DirectoryService; // If we contain an album assume we are an artist folder - return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, isMusicMediaFolder, directoryService, _logger, _fileSystem)) ? new MusicArtist() : null; + return args.FileSystemChildren.Where(i => (i.Attributes & FileAttributes.Directory) == FileAttributes.Directory).Any(i => MusicAlbumResolver.IsMusicAlbum(i.FullName, directoryService, _logger, _fileSystem, _libraryManager)) ? new MusicArtist() : null; } } -- cgit v1.2.3