mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Add option to use replaygain tags for audio (#10566)
* Add option to use replaygain tags for audio * Change regex to be specific * Use ffprobe for faster metadata grabs * Change regex to .Match
This commit is contained in:
parent
615089228a
commit
7b5c41c2a5
@ -31,6 +31,8 @@ namespace MediaBrowser.Model.Configuration
|
|||||||
|
|
||||||
public bool EnableLUFSScan { get; set; }
|
public bool EnableLUFSScan { get; set; }
|
||||||
|
|
||||||
|
public bool UseReplayGainTags { get; set; }
|
||||||
|
|
||||||
public bool EnableChapterImageExtraction { get; set; }
|
public bool EnableChapterImageExtraction { get; set; }
|
||||||
|
|
||||||
public bool ExtractChapterImagesDuringLibraryScan { get; set; }
|
public bool ExtractChapterImagesDuringLibraryScan { get; set; }
|
||||||
|
@ -61,6 +61,9 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||||||
[GeneratedRegex(@"I:\s+(.*?)\s+LUFS")]
|
[GeneratedRegex(@"I:\s+(.*?)\s+LUFS")]
|
||||||
private static partial Regex LUFSRegex();
|
private static partial Regex LUFSRegex();
|
||||||
|
|
||||||
|
[GeneratedRegex(@"REPLAYGAIN_TRACK_GAIN:\s+-?([0-9.]+)\s+dB")]
|
||||||
|
private static partial Regex ReplayGainTagRegex();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Probes the specified item for metadata.
|
/// Probes the specified item for metadata.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -104,8 +107,50 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
var libraryOptions = _libraryManager.GetLibraryOptions(item);
|
var libraryOptions = _libraryManager.GetLibraryOptions(item);
|
||||||
|
bool foundLUFSValue = false;
|
||||||
|
|
||||||
if (libraryOptions.EnableLUFSScan)
|
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)
|
||||||
{
|
{
|
||||||
using (var process = new Process()
|
using (var process = new Process()
|
||||||
{
|
{
|
||||||
@ -144,7 +189,8 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (!libraryOptions.EnableLUFSScan && !libraryOptions.UseReplayGainTags)
|
||||||
{
|
{
|
||||||
item.LUFS = DefaultLUFSValue;
|
item.LUFS = DefaultLUFSValue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user