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:
BinaryAlley committed 2026-10-14 13:40:28 +03:00
1 parent 4ffa81fffe
commit f29f89f31f
60 files changed
+4483 -68

No files matched your search

@@ -38,6 +38,11 @@ public class AudioMetadata : BaseMetadata
/// </summary>
public Optional<string> AudioCodec { get; }
/// <summary>
/// Gets the container of the audio, as read from the file itself, for example MP3, FLAC, OGG, AAC, MP4 or WAV.
/// </summary>
public Optional<string> Container { get; }
/// <summary>
/// Gets the bitrate of the audio in kbps.
/// </summary>
@@ -82,6 +87,7 @@ public class AudioMetadata : BaseMetadata
/// <param name="originalLanguage">The optional original language of the audio.</param>
/// <param name="bitDepth">The bit depth of the audio.</param>
/// <param name="audioCodec">The audio codec used.</param>
/// <param name="container">The container of the audio.</param>
/// <param name="genres">The genres of the audio.</param>
/// <param name="tags">The tags associated with the audio.</param>
/// <param name="bitrate">The bitrate of the audio in kbps.</param>
@@ -104,6 +110,7 @@ public class AudioMetadata : BaseMetadata
Optional<LanguageInfo> originalLanguage,
Optional<int> bitDepth,
Optional<string> audioCodec,
Optional<string> container,
Optional<int> bitrate,
Optional<string> acoustId,
Optional<decimal> replayGainTrackGain,
@@ -117,6 +124,7 @@ public class AudioMetadata : BaseMetadata
Channels = channels;
BitDepth = bitDepth;
AudioCodec = audioCodec;
Container = container;
Bitrate = bitrate;
AcoustId = acoustId;
ReplayGainTrackGain = replayGainTrackGain;
@@ -139,6 +147,7 @@ public class AudioMetadata : BaseMetadata
/// <param name="originalLanguage">The optional original language of the audio.</param>
/// <param name="bitDepth">The bit depth of the audio.</param>
/// <param name="audioCodec">The audio codec used.</param>
/// <param name="container">The container of the audio.</param>
/// <param name="genres">The genres of the audio.</param>
/// <param name="tags">The tags associated with the audio.</param>
/// <param name="bitrate">The bitrate of the audio in kbps.</param>
@@ -164,6 +173,7 @@ public class AudioMetadata : BaseMetadata
Optional<LanguageInfo> originalLanguage,
Optional<int> bitDepth,
Optional<string> audioCodec,
Optional<string> container,
Optional<int> bitrate,
Optional<string> acoustId,
Optional<decimal> replayGainTrackGain,
@@ -185,6 +195,7 @@ public class AudioMetadata : BaseMetadata
originalLanguage,
bitDepth,
audioCodec,
container,
bitrate,
acoustId,
replayGainTrackGain,
@@ -193,6 +204,38 @@ public class AudioMetadata : BaseMetadata
replayGainAlbumPeak);
}
/// <summary>
/// Creates a copy of this audio metadata with the provided <paramref name="container"/>, keeping every other property unchanged.
/// </summary>
/// <param name="container">The container of the audio.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a copy of this audio metadata with the provided container, or an error message.
/// </returns>
internal Result<AudioMetadata> WithContainer(Optional<string> container)
{
return Create(
Title,
OriginalTitle,
DurationInSeconds,
SampleRate,
Channels,
ReleaseInfo,
Description,
[.. Genres],
[.. Tags],
Language,
OriginalLanguage,
BitDepth,
AudioCodec,
container,
Bitrate,
AcoustId,
ReplayGainTrackGain,
ReplayGainTrackPeak,
ReplayGainAlbumGain,
ReplayGainAlbumPeak);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
@@ -206,6 +249,7 @@ public class AudioMetadata : BaseMetadata
yield return Channels;
yield return BitDepth;
yield return AudioCodec;
yield return Container;
yield return Bitrate;
yield return AcoustId;
yield return ReplayGainTrackGain;
@@ -347,7 +347,8 @@ public sealed class Track : Entity<TrackId>
/// </summary>
/// <remarks>
/// The file system path is intentionally not editable here: it is set only when the track is created by the scanner, so that a client
/// can never point an existing track at an arbitrary file of the host.
/// can never point an existing track at an arbitrary file of the host. The container is captured from the file itself and is not part of
/// an edit either, so an update that does not carry one keeps the container already stored for the track.
/// </remarks>
/// <param name="metadata">The audio metadata of the track.</param>
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
@@ -374,7 +375,16 @@ public sealed class Track : Entity<TrackId>
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId)
{
Metadata = metadata;
// The container is captured from the file itself and is never part of an edit, so an update that does not carry one keeps the stored container.
if (metadata.Container.HasValue)
Metadata = metadata;
else
{
Result<AudioMetadata> metadataWithStoredContainerResult = metadata.WithContainer(Metadata.Container);
if (metadataWithStoredContainerResult.IsFailure)
return metadataWithStoredContainerResult.Errors;
Metadata = metadataWithStoredContainerResult.Value;
}
Disambiguation = disambiguation;
TrackNumber = trackNumber;
DiscNumber = discNumber;