mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Fixes the release type detection of the music library path structure.
This commit is contained in:
1 parent
27c6c40b39
commit
443f4612f8
3 files changed
+51
-5
No files matched your search
+15
-4
@@ -52,12 +52,14 @@ internal sealed class MusicLibraryPathStructure
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the on-disk release type directory of the track stored at <paramref name="trackPath"/>, 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 <paramref name="artistName"/>, 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.
|
||||
/// </summary>
|
||||
/// <param name="trackPath">The file system path of the track whose release type directory is retrieved.</param>
|
||||
/// <param name="artistName">The name of the artist of the track, or <see langword="null"/> when it is not known.</param>
|
||||
/// <returns>The name of the on-disk release type directory, or <see langword="null"/> when the library does not use one.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+35
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user