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

@@ -216,6 +216,11 @@ internal sealed class Id3TagDto
/// </summary>
public string? AudioCodec { get; init; }
/// <summary>
/// Gets or initializes the container of the audio file of the track, for example MP3, FLAC, OGG, AAC, MP4 or WAV.
/// </summary>
public string? Container { get; init; }
/// <summary>
/// Gets or initializes the official website associated with the artist.
/// </summary>
@@ -164,6 +164,7 @@ internal static class Id3TagMapper
Channels: data.Channels,
BitDepth: data.BitDepth,
AudioCodec: NullIfWhiteSpace(data.AudioCodec),
Container: NullIfWhiteSpace(data.Container),
Bitrate: data.Bitrate,
MusicBrainzRecordingId: ParseGuid(data.MusicBrainzRecordingId),
MusicBrainzTrackId: ParseGuid(data.MusicBrainzReleaseTrackId),
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Plugins.ID3.Core.Tags;
/// <summary>
/// Resolves the canonical name of the container of an audio file from the concrete type the tagging library parsed it as.
/// </summary>
internal static class AudioContainerResolver
{
/// <summary>
/// Resolves the container of the audio file parsed by <paramref name="tagFile"/>.
/// </summary>
/// <param name="tagFile">The parsed audio file whose container is resolved.</param>
/// <returns>The canonical name of the container, for example MP3, FLAC, OGG, AAC, MP4 or WAV, or <see langword="null"/> when the container cannot be recognized.</returns>
public static string? Resolve(TagLib.File tagFile)
{
// The concrete type of the parsed file is the most reliable description of its container, because it is chosen by the parser from the
// actual bytes of the file, while the mime type only describes the extension. The scanning pipeline resolves the container the same way,
// so that the container captured during a scan and the one captured during metadata enrichment always agree.
return tagFile switch
{
TagLib.Mpeg.File => "MP3",
TagLib.Flac.File => "FLAC",
TagLib.Mpeg4.File => "MP4",
TagLib.Aac.File => "AAC",
TagLib.Ogg.File => "OGG",
TagLib.Riff.File => "WAV",
TagLib.Aiff.File => "AIFF",
TagLib.Ape.File => "APE",
TagLib.WavPack.File => "WAVPACK",
TagLib.Asf.File => "WMA",
TagLib.Dsf.File => "DSF",
TagLib.Matroska.File => "MATROSKA",
TagLib.MusePack.File => "MPC",
TagLib.Audible.File => "AA",
_ => ResolveFromMimeType(tagFile.MimeType)
};
}
/// <summary>
/// Resolves the container from the mime type reported by the tagging library, for the containers that have no dedicated parser.
/// </summary>
/// <param name="mimeType">The mime type reported by the tagging library.</param>
/// <returns>The name of the container, or <see langword="null"/> when it cannot be derived.</returns>
public static string? ResolveFromMimeType(string? mimeType)
{
if (string.IsNullOrWhiteSpace(mimeType))
return null;
// The library reports its mime types with the "taglib/" prefix, so only the last segment names the container.
string[] segments = mimeType.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
string? container = segments.Length > 0 ? segments[^1] : null;
return string.IsNullOrWhiteSpace(container) ? null : container.ToUpperInvariant();
}
}
@@ -166,6 +166,7 @@ internal sealed class Id3TagReader
BitDepth = audioProperties.BitsPerSample > 0 ? audioProperties.BitsPerSample : null,
Bitrate = audioProperties.AudioBitrate > 0 ? audioProperties.AudioBitrate : null,
AudioCodec = NullIfWhiteSpace(audioProperties.Description),
Container = AudioContainerResolver.Resolve(tagFile),
Website = NullIfWhiteSpace(GetExtendedField(extendedFields, "WOAR", "website")),
MusicBrainzArtistId = NullIfWhiteSpace(tag.MusicBrainzArtistId),
MusicBrainzReleaseArtistId = NullIfWhiteSpace(tag.MusicBrainzReleaseArtistId),
@@ -183,6 +183,7 @@ internal static partial class MusicBrainzMapper
Channels: null,
BitDepth: null,
AudioCodec: null,
Container: null,
Bitrate: null,
MusicBrainzRecordingId: ParseGuid(recording.Id),
MusicBrainzTrackId: null,