aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
diff options
context:
space:
mode:
authorBrian Howe <howe.m.brian@gmail.com>2024-02-27 21:07:30 -0600
committerBrian Howe <howe.m.brian@gmail.com>2024-02-27 21:07:30 -0600
commit54eb81395ef8d3d4cb064b56361ce94fc72b38b5 (patch)
tree73240b556055557b0ae034ef5d5ba60cb5cb051e /MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
parent7f1fec688cc1a6f7f69fa5b059af01cf9c456d3f (diff)
parent4786901bb796c3e912f13b686571fde8d16f49c5 (diff)
Merge branch 'master' into bhowe34/fix-replace-missing-metadata-for-music
Diffstat (limited to 'MediaBrowser.Providers/MediaInfo/AudioFileProber.cs')
-rw-r--r--MediaBrowser.Providers/MediaInfo/AudioFileProber.cs50
1 files changed, 48 insertions, 2 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
index 5d41542e2..f68faab04 100644
--- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
+++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
@@ -61,6 +61,9 @@ namespace MediaBrowser.Providers.MediaInfo
[GeneratedRegex(@"I:\s+(.*?)\s+LUFS")]
private static partial Regex LUFSRegex();
+ [GeneratedRegex(@"REPLAYGAIN_TRACK_GAIN:\s+-?([0-9.]+)\s+dB")]
+ private static partial Regex ReplayGainTagRegex();
+
/// <summary>
/// Probes the specified item for metadata.
/// </summary>
@@ -104,8 +107,50 @@ namespace MediaBrowser.Providers.MediaInfo
}
var libraryOptions = _libraryManager.GetLibraryOptions(item);
+ bool foundLUFSValue = false;
+
+ if (libraryOptions.UseReplayGainTags)
+ {
+ using (var process = new Process()
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ FileName = _mediaEncoder.ProbePath,
+ Arguments = $"-hide_banner -i \"{path}\"",
+ RedirectStandardOutput = false,
+ RedirectStandardError = true
+ },
+ })
+ {
+ try
+ {
+ process.Start();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error starting ffmpeg");
+
+ throw;
+ }
+
+ using var reader = process.StandardError;
+ var output = await reader.ReadToEndAsync(cancellationToken).ConfigureAwait(false);
+ cancellationToken.ThrowIfCancellationRequested();
+ Match split = ReplayGainTagRegex().Match(output);
+
+ if (split.Success)
+ {
+ item.LUFS = DefaultLUFSValue - float.Parse(split.Groups[1].ValueSpan, CultureInfo.InvariantCulture.NumberFormat);
+ foundLUFSValue = true;
+ }
+ else
+ {
+ item.LUFS = DefaultLUFSValue;
+ }
+ }
+ }
- if (libraryOptions.EnableLUFSScan)
+ if (libraryOptions.EnableLUFSScan && !foundLUFSValue)
{
using (var process = new Process()
{
@@ -144,7 +189,8 @@ namespace MediaBrowser.Providers.MediaInfo
}
}
}
- else
+
+ if (!libraryOptions.EnableLUFSScan && !libraryOptions.UseReplayGainTags)
{
item.LUFS = DefaultLUFSValue;
}