diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructure.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructure.cs
index 714a60f4..da99d9f6 100644
--- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructure.cs
+++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructure.cs
@@ -52,12 +52,14 @@ internal sealed class MusicLibraryPathStructure
///
/// Gets the name of the on-disk release type directory of the track stored at , when the structure of the library
- /// uses one. The directory is the parent of the album directory, and it is only used when its name is a known release type, so that the artist
- /// directory of a flat library is not mistaken for a release type.
+ /// uses one. The directory is the parent of the album directory, and it is only used when its name is a known release type and it is not the
+ /// directory of , because the parent of the album directory of a library that has no release type directory is
+ /// the artist directory, which must not be mistaken for a release type.
///
/// The file system path of the track whose release type directory is retrieved.
+ /// The name of the artist of the track, or when it is not known.
/// The name of the on-disk release type directory, or when the library does not use one.
- public string? GetReleaseTypeDirectoryName(string trackPath)
+ public string? GetReleaseTypeDirectoryName(string trackPath, string? artistName = null)
{
string albumDirectory = GetAlbumDirectory(trackPath);
string? releaseTypeDirectory = GetParentDirectoryPath(albumDirectory);
@@ -65,7 +67,16 @@ internal sealed class MusicLibraryPathStructure
return null;
string releaseTypeName = GetLastSegment(releaseTypeDirectory);
- return Enum.TryParse(releaseTypeName, ignoreCase: true, out MusicReleaseType _) ? releaseTypeName : null;
+ // A numeric directory name parses to an enumeration member that is not defined, so it is rejected explicitly, together with any other
+ // name that is not a known release type.
+ if (!Enum.TryParse(releaseTypeName, ignoreCase: true, out MusicReleaseType releaseType) || !Enum.IsDefined(releaseType))
+ return null;
+
+ // The artist directory of a library that has no release type directory is the parent of the album directory, so it is not a release type.
+ if (!string.IsNullOrWhiteSpace(artistName) && string.Equals(releaseTypeName, artistName, StringComparison.OrdinalIgnoreCase))
+ return null;
+
+ return releaseTypeName;
}
///
diff --git a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs
index 1a4e4c05..8697d40d 100644
--- a/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs
+++ b/src/Lumina.Infrastructure/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicMediaLibraryScanArtworkEnricher.cs
@@ -370,7 +370,7 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
// The release type directory groups the artwork of the releases of the artist that share a title, so the album, the single and the live release of the same songs do not collide.
// It is read from the file system, because the structure on disk is the source of truth of the release type of an album.
- string? releaseTypeName = _musicLibraryPathStructure.GetReleaseTypeDirectoryName(firstTrackPath);
+ string? releaseTypeName = _musicLibraryPathStructure.GetReleaseTypeDirectoryName(firstTrackPath, albumEntity.Artist?.Name);
return await EnrichArtworkAsync(
artworkLookup,
diff --git a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructureTests.cs b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructureTests.cs
index 032222b0..2ac6f06a 100644
--- a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructureTests.cs
+++ b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Core/MediaLibrary/Management/Scanning/Jobs/Audio/Music/MusicLibraryPathStructureTests.cs
@@ -157,4 +157,39 @@ public class MusicLibraryPathStructureTests
// Assert
Assert.Null(result);
}
+
+ [Theory]
+ [InlineData('\\', "Live")] // release type name used as the artist directory name, Windows separated path
+ [InlineData('/', "Live")] // release type name used as the artist directory name, Unix separated path
+ [InlineData('\\', "42")] // numeric artist directory name, Windows separated path
+ [InlineData('/', "42")] // numeric artist directory name, Unix separated path
+ public void GetReleaseTypeDirectoryName_WhenTheArtistDirectoryIsNamedLikeAReleaseType_ShouldReturnNull(char separator, string artistName)
+ {
+ // Arrange
+ _mockPathService.PathSeparator.Returns(separator);
+ // The library uses no release type directory, so the parent of the album directory is the artist directory.
+ string trackPath = string.Join(separator, "music", artistName, "a-night-at-the-opera", "bohemian-rhapsody.flac");
+
+ // Act
+ string? result = _sut.GetReleaseTypeDirectoryName(trackPath, artistName);
+
+ // Assert
+ Assert.Null(result);
+ }
+
+ [Theory]
+ [InlineData('\\')] // Windows separated path
+ [InlineData('/')] // Unix separated path
+ public void GetReleaseTypeDirectoryName_WhenAReleaseTypeDirectoryDiffersFromTheArtistDirectory_ShouldReturnIt(char separator)
+ {
+ // Arrange
+ _mockPathService.PathSeparator.Returns(separator);
+ string trackPath = string.Join(separator, "music", "Queen", "Live", "a-night-at-the-opera", "bohemian-rhapsody.flac");
+
+ // Act
+ string? result = _sut.GetReleaseTypeDirectoryName(trackPath, "Queen");
+
+ // Assert
+ Assert.Equal("Live", result);
+ }
}