From 61fa325ef05daac7c5105623d2de435ec94ef6a7 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Mon, 28 Mar 2022 23:11:21 +0200 Subject: Extend music parsing --- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/Library') diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index da00b9cfa..5e05ddfb1 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -98,7 +99,15 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio // 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 + foreach (var subfolder in _namingOptions.ArtistSubfolders) + { + if (Path.GetDirectoryName(args.Path.AsSpan()).Equals(subfolder, StringComparison.OrdinalIgnoreCase)) + { + _logger.LogDebug("Found release folder: {Path}", args.Path); + return false; + } + } + if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService)) { return true; -- cgit v1.2.3 From cfd1db16387b75c340f6e2e7f453a8a97be02eaf Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Tue, 29 Mar 2022 20:31:59 +0200 Subject: Prevent MusicArtist creation for artist subfolders --- .../Library/Resolvers/Audio/MusicArtistResolver.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/Library') diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index 210ed0953..b7c1724c0 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -61,7 +61,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase); - // If there's a collection type and it's not music, it can't be a series + // If there's a collection type and it's not music, it can't be a music artist if (!isMusicMediaFolder) { return null; @@ -87,6 +87,15 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio var result = Parallel.ForEach(directories, (fileSystemInfo, state) => { + foreach (var subfolder in _namingOptions.ArtistSubfolders) + { + if (fileSystemInfo.Name.Equals(subfolder, StringComparison.OrdinalIgnoreCase)) + { + // stop once we see a artist subfolder + state.Stop(); + } + } + if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, directoryService)) { // stop once we see a music album -- cgit v1.2.3 From 42fc02cab6a44ff3fd891c9f9afa669711b4215d Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 31 Mar 2022 16:17:37 +0200 Subject: Add xmldocs --- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 14 +++--- .../Library/Resolvers/Audio/MusicArtistResolver.cs | 19 ++++---- .../Providers/ICustomMetadataProvider.cs | 6 +-- .../MediaInfo/AudioFileProber.cs | 33 +++++++++----- MediaBrowser.Providers/MediaInfo/ProbeProvider.cs | 50 ++++++++++++++++++++-- .../Music/AlbumMetadataService.cs | 13 +++++- .../Music/AudioMetadataService.cs | 13 +++++- 7 files changed, 112 insertions(+), 36 deletions(-) (limited to 'Emby.Server.Implementations/Library') diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 5e05ddfb1..2674d1355 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -19,7 +19,7 @@ using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Library.Resolvers.Audio { /// - /// Class MusicAlbumResolver. + /// The music album resolver. /// public class MusicAlbumResolver : ItemResolver { @@ -93,12 +93,12 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio /// Determine if the supplied resolve args should be considered a music album. /// /// The args. - /// true if [is music album] [the specified args]; otherwise, false. + /// true if [is music album] [the specified args], false otherwise. 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 is a artist subfolder it's not a music album foreach (var subfolder in _namingOptions.ArtistSubfolders) { if (Path.GetDirectoryName(args.Path.AsSpan()).Equals(subfolder, StringComparison.OrdinalIgnoreCase)) @@ -108,6 +108,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio } } + // If args contains music it's a music album if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService)) { return true; @@ -120,22 +121,23 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio /// /// Determine if the supplied list contains what we should consider music. /// + /// true if the provided path list contains music, false otherwise. private bool ContainsMusic( ICollection list, bool allowSubfolders, IDirectoryService directoryService) { - // check for audio files before digging down into directories + // Check for audio files before digging down into directories var foundAudioFile = list.Any(fileSystemInfo => !fileSystemInfo.IsDirectory && AudioFileParser.IsAudioFile(fileSystemInfo.FullName, _namingOptions)); if (foundAudioFile) { - // at least one audio file exists + // At least one audio file exists return true; } if (!allowSubfolders) { - // not music since no audio file exists and we're not looking into subfolders + // Not music since no audio file exists and we're not looking into subfolders return false; } diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index b7c1724c0..2538c2b5b 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Library.Resolvers.Audio { /// - /// Class MusicArtistResolver. + /// The music artist resolver. /// public class MusicArtistResolver : ItemResolver { @@ -23,8 +23,8 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio /// /// Initializes a new instance of the class. /// - /// The logger for the created instances. - /// The naming options. + /// Instance of the interface. + /// The . public MusicArtistResolver( ILogger logger, NamingOptions namingOptions) @@ -40,10 +40,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio public override ResolverPriority Priority => ResolverPriority.Second; /// - /// Resolves the specified args. + /// Resolves the specified resolver arguments. /// - /// The args. - /// MusicArtist. + /// The resolver arguments. + /// A . protected override MusicArtist Resolve(ItemResolveArgs args) { if (!args.IsDirectory) @@ -82,23 +82,24 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio var albumResolver = new MusicAlbumResolver(_logger, _namingOptions); - // If we contain an album assume we are an artist folder var directories = args.FileSystemChildren.Where(i => i.IsDirectory); var result = Parallel.ForEach(directories, (fileSystemInfo, state) => { + // If we contain a artist subfolder assume we are an artist folder foreach (var subfolder in _namingOptions.ArtistSubfolders) { if (fileSystemInfo.Name.Equals(subfolder, StringComparison.OrdinalIgnoreCase)) { - // stop once we see a artist subfolder + // Stop once we see an artist subfolder state.Stop(); } } + // If we contain a music album assume we are an artist folder if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, directoryService)) { - // stop once we see a music album + // Stop once we see a music album state.Stop(); } }); diff --git a/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs b/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs index 32a9cbef2..14428df5b 100644 --- a/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs +++ b/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs @@ -18,9 +18,9 @@ namespace MediaBrowser.Controller.Providers /// Fetches the metadata asynchronously. /// /// The item. - /// The options. - /// The cancellation token. - /// Task{ItemUpdateType}. + /// The . + /// The . + /// A fetching the . Task FetchAsync(TItemType item, MetadataRefreshOptions options, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs index 2591e880f..2b26b3137 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs @@ -1,7 +1,5 @@ #nullable disable -#pragma warning disable CS1591 - using System; using System.Collections.Generic; using System.Linq; @@ -21,6 +19,9 @@ using TagLib; namespace MediaBrowser.Providers.MediaInfo { + /// + /// Probes audio files for metadata. + /// public class AudioFileProber { private readonly IMediaEncoder _mediaEncoder; @@ -28,6 +29,13 @@ namespace MediaBrowser.Providers.MediaInfo private readonly ILibraryManager _libraryManager; private readonly IMediaSourceManager _mediaSourceManager; + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public AudioFileProber( IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder, @@ -40,6 +48,14 @@ namespace MediaBrowser.Providers.MediaInfo _mediaSourceManager = mediaSourceManager; } + /// + /// Probes the specified item for metadata. + /// + /// The item to probe. + /// The . + /// The . + /// The type of item to resolve. + /// A probing the item for metadata. public async Task Probe( T item, MetadataRefreshOptions options, @@ -80,9 +96,9 @@ namespace MediaBrowser.Providers.MediaInfo /// /// Fetches the specified audio. /// - /// The audio. - /// The media information. - /// The cancellation token. + /// The . + /// The . + /// The . protected void Fetch(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, CancellationToken cancellationToken) { audio.Container = mediaInfo.Container; @@ -91,18 +107,15 @@ namespace MediaBrowser.Providers.MediaInfo audio.RunTimeTicks = mediaInfo.RunTimeTicks; audio.Size = mediaInfo.Size; - // var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.'); - // audio.Container = extension; - FetchDataFromTags(audio); _itemRepo.SaveMediaStreams(audio.Id, mediaInfo.MediaStreams, cancellationToken); } /// - /// Fetches data from the tags dictionary. + /// Fetches data from the tags. /// - /// The audio. + /// The . private void FetchDataFromTags(Audio audio) { var file = TagLib.File.Create(audio.Path); diff --git a/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs index 54c12a8f1..659136607 100644 --- a/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs @@ -1,7 +1,5 @@ #nullable disable -#pragma warning disable CS1591 - using System; using System.IO; using System.Linq; @@ -27,6 +25,9 @@ using Microsoft.Extensions.Logging; namespace MediaBrowser.Providers.MediaInfo { + /// + /// The probe provider. + /// public class ProbeProvider : ICustomMetadataProvider, ICustomMetadataProvider, ICustomMetadataProvider, @@ -46,6 +47,22 @@ namespace MediaBrowser.Providers.MediaInfo private readonly AudioFileProber _audioProber; private readonly Task _cachedTask = Task.FromResult(ItemUpdateType.None); + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the . + /// Instance of the interface. + /// The . public ProbeProvider( IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder, @@ -81,11 +98,13 @@ namespace MediaBrowser.Providers.MediaInfo _subtitleResolver); } - public string Name => "filemetadataprober"; + /// + public string Name => "Probe Provider"; - // Run last + /// public int Order => 100; + /// public bool HasChanged(BaseItem item, IDirectoryService directoryService) { var video = item as Video; @@ -127,41 +146,56 @@ namespace MediaBrowser.Providers.MediaInfo return false; } + /// public Task FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } + /// public Task FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } + /// public Task FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } + /// public Task FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } + /// public Task FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchVideoInfo(item, options, cancellationToken); } + /// public Task FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchAudioInfo(item, options, cancellationToken); } + /// public Task FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken) { return FetchAudioInfo(item, options, cancellationToken); } + /// + /// Fetches video information for an item. + /// + /// The item. + /// The . + /// The . + /// The type of item to resolve. + /// A fetching the for an item. public Task FetchVideoInfo(T item, MetadataRefreshOptions options, CancellationToken cancellationToken) where T : Video { @@ -208,6 +242,14 @@ namespace MediaBrowser.Providers.MediaInfo .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith('#')); } + /// + /// Fetches audio information for an item. + /// + /// The item. + /// The . + /// The . + /// The type of item to resolve. + /// A fetching the for an item. public Task FetchAudioInfo(T item, MetadataRefreshOptions options, CancellationToken cancellationToken) where T : Audio { diff --git a/MediaBrowser.Providers/Music/AlbumMetadataService.cs b/MediaBrowser.Providers/Music/AlbumMetadataService.cs index b8426f31c..1a8e20be3 100644 --- a/MediaBrowser.Providers/Music/AlbumMetadataService.cs +++ b/MediaBrowser.Providers/Music/AlbumMetadataService.cs @@ -1,5 +1,3 @@ -#pragma warning disable CS1591 - using System; using System.Collections.Generic; using System.Linq; @@ -15,8 +13,19 @@ using Microsoft.Extensions.Logging; namespace MediaBrowser.Providers.Music { + /// + /// The album metadata service. + /// public class AlbumMetadataService : MetadataService { + /// + /// Initializes a new instance of the class. + /// + /// Instance of the . + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public AlbumMetadataService( IServerConfigurationManager serverConfigurationManager, ILogger logger, diff --git a/MediaBrowser.Providers/Music/AudioMetadataService.cs b/MediaBrowser.Providers/Music/AudioMetadataService.cs index 64f40ef49..7c38d0bcf 100644 --- a/MediaBrowser.Providers/Music/AudioMetadataService.cs +++ b/MediaBrowser.Providers/Music/AudioMetadataService.cs @@ -1,5 +1,3 @@ -#pragma warning disable CS1591 - using System; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities.Audio; @@ -12,8 +10,19 @@ using Microsoft.Extensions.Logging; namespace MediaBrowser.Providers.Music { + /// + /// The audio metadata service. + /// public class AudioMetadataService : MetadataService { + /// + /// Initializes a new instance of the class. + /// + /// Instance of the . + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public AudioMetadataService( IServerConfigurationManager serverConfigurationManager, ILogger logger, -- cgit v1.2.3 From 6c6f89acc306f2dd9237ce618f024f8630f70696 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Fri, 7 Oct 2022 14:14:21 +0200 Subject: Apply review suggestions --- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 6 +++--- MediaBrowser.Providers/MediaInfo/AudioFileProber.cs | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'Emby.Server.Implementations/Library') diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 2674d1355..a922e3685 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -83,7 +83,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio /// /// The path to check. /// The directory service. - /// true if the provided path points to a music album, false otherwise. + /// true if the provided path points to a music album; otherwise, false. public bool IsMusicAlbum(string path, IDirectoryService directoryService) { return ContainsMusic(directoryService.GetFileSystemEntries(path), true, directoryService); @@ -93,7 +93,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio /// Determine if the supplied resolve args should be considered a music album. /// /// The args. - /// true if [is music album] [the specified args], false otherwise. + /// true if [is music album] [the specified args]; otherwise, false. private bool IsMusicAlbum(ItemResolveArgs args) { if (args.IsDirectory) @@ -121,7 +121,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio /// /// Determine if the supplied list contains what we should consider music. /// - /// true if the provided path list contains music, false otherwise. + /// true if the provided path list contains music; otherwise, false. private bool ContainsMusic( ICollection list, bool allowSubfolders, diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs index 42d85bb0c..7f8ecd578 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -120,7 +118,7 @@ namespace MediaBrowser.Providers.MediaInfo { var file = TagLib.File.Create(audio.Path); var tagTypes = file.TagTypesOnDisk; - Tag tags = null; + Tag tags = new TagLib.Id3v2.Tag(); if (tagTypes.HasFlag(TagTypes.Id3v2)) { @@ -151,7 +149,7 @@ namespace MediaBrowser.Providers.MediaInfo tags = file.GetTag(TagTypes.Id3v1); } - if (tags != null) + if (tags.IsEmpty) { if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast)) { -- cgit v1.2.3