mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Captures the audio container of the music tracks
Adds a Container to the audio metadata, captured with TagLibSharp from the concrete type of the parsed file during the music library scan and stored on the track through a new column and an EF migration. The container is refreshed when a file changes, survives track and artist edits and provider enrichment, and is exposed read-only in the track responses, never settable through a request. Extracts the container resolution into a testable resolver used by the scan pipeline and the ID3 plugin, refuses to read a file that is itself a reparse point during extraction, and updates the endpoint summaries, the API and domain documentation, and the tests.
This commit is contained in:
1 parent
4ffa81fffe
commit
f29f89f31f
60 files changed
+4483
-68
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Infrastructure.Core.MediaLibrary.AudioLibrary.MusicLibrary.Metadata;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.UnitTests.Core.MediaLibrary.AudioLibrary.MusicLibrary.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AudioContainerResolver"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AudioContainerResolverTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(null, null)] // an absent mime type leaves the container unrecognized
|
||||
[InlineData("", null)] // an empty mime type leaves the container unrecognized
|
||||
[InlineData(" ", null)] // a blank mime type leaves the container unrecognized
|
||||
[InlineData("taglib/wav", "WAV")] // the taglib prefix is dropped and the container is upper cased
|
||||
[InlineData("taglib/png", "PNG")] // a container the resolver has no dedicated parser for still yields its name
|
||||
[InlineData("audio/x-wavpack", "X-WAVPACK")] // the last segment of a standard mime type names the container
|
||||
public void ResolveFromMimeType_WhenCalled_ShouldReturnTheContainerNamedByTheMimeType(string? mimeType, string? expectedContainer)
|
||||
{
|
||||
// Act
|
||||
string? container = AudioContainerResolver.ResolveFromMimeType(mimeType);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedContainer, container);
|
||||
}
|
||||
}
|
||||
+28
@@ -91,6 +91,34 @@ public class MusicMetadataAggregatorTests
|
||||
Assert.Equal(360, merged.DurationInSeconds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_WhenTheFirstAudioMetadataHasAContainer_ShouldKeepTheFirstContainer()
|
||||
{
|
||||
// Arrange
|
||||
AudioMetadataDto first = _audioMetadataDtoFixture.Create(container: "MP3");
|
||||
AudioMetadataDto second = _audioMetadataDtoFixture.Create(container: "FLAC");
|
||||
|
||||
// Act
|
||||
AudioMetadataDto merged = MusicMetadataAggregator.Merge(first, second);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("MP3", merged.Container);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_WhenTheFirstAudioMetadataHasNoContainer_ShouldTakeTheSecondContainer()
|
||||
{
|
||||
// Arrange
|
||||
AudioMetadataDto first = _audioMetadataDtoFixture.Create(includeContainer: false);
|
||||
AudioMetadataDto second = _audioMetadataDtoFixture.Create(container: "FLAC");
|
||||
|
||||
// Act
|
||||
AudioMetadataDto merged = MusicMetadataAggregator.Merge(first, second);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("FLAC", merged.Container);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Merge_WhenTheFirstMetadataHasOnlyAReleaseYearAndTheSecondHasAReleaseDate_ShouldDeriveTheYearFromTheDate()
|
||||
{
|
||||
|
||||
+27
@@ -116,6 +116,33 @@ public class MusicMediaLibraryScanItemMaterializerTests
|
||||
AlbumEntity secondAlbum = artist.Albums.Single(album => album.MusicBrainzReleaseId == secondReleaseId);
|
||||
Assert.Equal(firstRecordingId, Assert.Single(firstAlbum.Tracks).MusicBrainzRecordingId);
|
||||
Assert.Equal(secondRecordingId, Assert.Single(secondAlbum.Tracks).MusicBrainzRecordingId);
|
||||
// The container read from the file itself is carried from the staged metadata to the materialized track.
|
||||
Assert.Equal(firstStagedItem.Container, Assert.Single(firstAlbum.Tracks).Container);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MaterializeItemsAsync_WhenTheStagedItemHasNoContainer_ShouldMaterializeTheTrackWithoutAContainer()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryScanItemMetadataEntity stagedItem = _musicLibraryScanItemMetadataEntityFixture.Create(
|
||||
libraryId: _libraryId,
|
||||
artistName: "Some Artist",
|
||||
releaseName: "Some Release",
|
||||
path: "/music/some-artist/some-release/track.mp3",
|
||||
includeMusicBrainzTags: false,
|
||||
includeContainer: false);
|
||||
_mockStagedMetadataRepository.GetByScanIdAsync(_scanId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicLibraryScanItemMetadataEntity>>([stagedItem]));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.MaterializeItemsAsync(_mockUnitOfWork, _libraryId, _scanId, [stagedItem.Path], CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsSuccess);
|
||||
ArtistEntity artist = Assert.Single(_insertedArtists);
|
||||
AlbumEntity album = Assert.Single(artist.Albums);
|
||||
// A file whose container the scan could not recognize materializes its track without a container, rather than failing the scan.
|
||||
Assert.Null(Assert.Single(album.Tracks).Container);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in new issue
Block a user