aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers/MediaInfo/AudioFileProber.cs')
-rw-r--r--MediaBrowser.Providers/MediaInfo/AudioFileProber.cs99
1 files changed, 86 insertions, 13 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
index b8578c46f..44f998742 100644
--- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
+++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
@@ -14,6 +17,7 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
+using Microsoft.Extensions.Logging;
using TagLib;
namespace MediaBrowser.Providers.MediaInfo
@@ -21,8 +25,12 @@ namespace MediaBrowser.Providers.MediaInfo
/// <summary>
/// Probes audio files for metadata.
/// </summary>
- public class AudioFileProber
+ public partial class AudioFileProber
{
+ // Default LUFS value for use with the web interface, at -18db gain will be 1(no db gain).
+ private const float DefaultLUFSValue = -18;
+
+ private readonly ILogger<AudioFileProber> _logger;
private readonly IMediaEncoder _mediaEncoder;
private readonly IItemRepository _itemRepo;
private readonly ILibraryManager _libraryManager;
@@ -31,22 +39,28 @@ namespace MediaBrowser.Providers.MediaInfo
/// <summary>
/// Initializes a new instance of the <see cref="AudioFileProber"/> class.
/// </summary>
+ /// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
/// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param>
/// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param>
/// <param name="itemRepo">Instance of the <see cref="IItemRepository"/> interface.</param>
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
public AudioFileProber(
+ ILogger<AudioFileProber> logger,
IMediaSourceManager mediaSourceManager,
IMediaEncoder mediaEncoder,
IItemRepository itemRepo,
ILibraryManager libraryManager)
{
+ _logger = logger;
_mediaEncoder = mediaEncoder;
_itemRepo = itemRepo;
_libraryManager = libraryManager;
_mediaSourceManager = mediaSourceManager;
}
+ [GeneratedRegex("I:\\s+(.*?)\\s+LUFS")]
+ private static partial Regex LUFSRegex();
+
/// <summary>
/// Probes the specified item for metadata.
/// </summary>
@@ -89,6 +103,55 @@ namespace MediaBrowser.Providers.MediaInfo
Fetch(item, result, cancellationToken);
}
+ var libraryOptions = _libraryManager.GetLibraryOptions(item);
+
+ if (libraryOptions.EnableLUFSScan)
+ {
+ string output;
+ using (var process = new Process()
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ FileName = _mediaEncoder.EncoderPath,
+ Arguments = $"-hide_banner -i \"{path}\" -af ebur128=framelog=verbose -f null -",
+ RedirectStandardOutput = false,
+ RedirectStandardError = true
+ },
+ })
+ {
+ try
+ {
+ process.Start();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error starting ffmpeg");
+
+ throw;
+ }
+
+ using var reader = process.StandardError;
+ output = await reader.ReadToEndAsync(cancellationToken).ConfigureAwait(false);
+ cancellationToken.ThrowIfCancellationRequested();
+ MatchCollection split = LUFSRegex().Matches(output);
+
+ if (split.Count != 0)
+ {
+ item.LUFS = float.Parse(split[0].Groups[1].ValueSpan, CultureInfo.InvariantCulture.NumberFormat);
+ }
+ else
+ {
+ item.LUFS = DefaultLUFSValue;
+ }
+ }
+ }
+ else
+ {
+ item.LUFS = DefaultLUFSValue;
+ }
+
+ _logger.LogDebug("LUFS for {ItemName} is {LUFS}.", item.Name, item.LUFS);
+
return ItemUpdateType.MetadataImport;
}
@@ -161,30 +224,39 @@ namespace MediaBrowser.Providers.MediaInfo
var albumArtists = tags.AlbumArtists;
foreach (var albumArtist in albumArtists)
{
- PeopleHelper.AddPerson(people, new PersonInfo
+ if (!string.IsNullOrEmpty(albumArtist))
{
- Name = albumArtist,
- Type = PersonKind.AlbumArtist
- });
+ PeopleHelper.AddPerson(people, new PersonInfo
+ {
+ Name = albumArtist,
+ Type = PersonKind.AlbumArtist
+ });
+ }
}
var performers = tags.Performers;
foreach (var performer in performers)
{
- PeopleHelper.AddPerson(people, new PersonInfo
+ if (!string.IsNullOrEmpty(performer))
{
- Name = performer,
- Type = PersonKind.Artist
- });
+ PeopleHelper.AddPerson(people, new PersonInfo
+ {
+ Name = performer,
+ Type = PersonKind.Artist
+ });
+ }
}
foreach (var composer in tags.Composers)
{
- PeopleHelper.AddPerson(people, new PersonInfo
+ if (!string.IsNullOrEmpty(composer))
{
- Name = composer,
- Type = PersonKind.Composer
- });
+ PeopleHelper.AddPerson(people, new PersonInfo
+ {
+ Name = composer,
+ Type = PersonKind.Composer
+ });
+ }
}
_libraryManager.UpdatePeople(audio, people);
@@ -196,6 +268,7 @@ namespace MediaBrowser.Providers.MediaInfo
audio.Album = tags.Album;
audio.IndexNumber = Convert.ToInt32(tags.Track);
audio.ParentIndexNumber = Convert.ToInt32(tags.Disc);
+
if (tags.Year != 0)
{
var year = Convert.ToInt32(tags.Year);