aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2024-04-24 16:09:01 +0200
committerGitHub <noreply@github.com>2024-04-24 08:09:01 -0600
commit428283f78751df30b44992c883e14babd6b3ce27 (patch)
tree6434546162f16bdaccf8295607a54b7241dc4cdf
parent3c159822b5d2bffea843d0cd5c90138dc30fc000 (diff)
Always scan ReplayGain tag (#11418)
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs2
-rw-r--r--MediaBrowser.Model/Configuration/LibraryOptions.cs2
-rw-r--r--MediaBrowser.Providers/MediaInfo/AudioFileProber.cs62
3 files changed, 7 insertions, 59 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index c1d9ecbdf..474b093d5 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -135,7 +135,7 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
/// <value>The LUFS Value.</value>
[JsonIgnore]
- public float LUFS { get; set; }
+ public float? LUFS { get; set; }
/// <summary>
/// Gets or sets the channel identifier.
diff --git a/MediaBrowser.Model/Configuration/LibraryOptions.cs b/MediaBrowser.Model/Configuration/LibraryOptions.cs
index e777d5fd8..7ce75b2bc 100644
--- a/MediaBrowser.Model/Configuration/LibraryOptions.cs
+++ b/MediaBrowser.Model/Configuration/LibraryOptions.cs
@@ -35,8 +35,6 @@ namespace MediaBrowser.Model.Configuration
public bool EnableLUFSScan { get; set; }
- public bool UseReplayGainTags { get; set; }
-
public bool EnableChapterImageExtraction { get; set; }
public bool ExtractChapterImagesDuringLibraryScan { get; set; }
diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
index 1ca57c36e..17d2ab71d 100644
--- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
+++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
@@ -70,9 +70,6 @@ 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>
@@ -116,50 +113,7 @@ 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 && !foundLUFSValue)
+ if (libraryOptions.EnableLUFSScan && item.LUFS is null)
{
using (var process = new Process()
{
@@ -192,18 +146,9 @@ namespace MediaBrowser.Providers.MediaInfo
{
item.LUFS = float.Parse(split[0].Groups[1].ValueSpan, CultureInfo.InvariantCulture.NumberFormat);
}
- else
- {
- item.LUFS = DefaultLUFSValue;
- }
}
}
- if (!libraryOptions.EnableLUFSScan && !libraryOptions.UseReplayGainTags)
- {
- item.LUFS = DefaultLUFSValue;
- }
-
_logger.LogDebug("LUFS for {ItemName} is {LUFS}.", item.Name, item.LUFS);
return ItemUpdateType.MetadataImport;
@@ -392,6 +337,11 @@ namespace MediaBrowser.Providers.MediaInfo
: audio.Genres;
}
+ if (!double.IsNaN(tags.ReplayGainTrackGain))
+ {
+ audio.LUFS = DefaultLUFSValue - (float)tags.ReplayGainTrackGain;
+ }
+
if (options.ReplaceAllMetadata || !audio.TryGetProviderId(MetadataProvider.MusicBrainzArtist, out _))
{
audio.SetProviderId(MetadataProvider.MusicBrainzArtist, tags.MusicBrainzArtistId);