Prechádzať zdrojové kódy

Add performers to the ffprobe normalization for audio

MrTimscampi 3 rokov pred
rodič
commit
f35a527608

+ 21 - 0
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -7,6 +7,7 @@ using System.Globalization;
 using System.IO;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Xml;
 using Jellyfin.Extensions;
 using MediaBrowser.Controller.Library;
@@ -1111,6 +1112,26 @@ namespace MediaBrowser.MediaEncoding.Probing
                 }
             }
 
+            if (tags.TryGetValue("performer", out var performer) && !string.IsNullOrWhiteSpace(performer))
+            {
+                foreach (var person in Split(performer, false))
+                {
+                    Regex pattern = new Regex(@"(?<name>.*) \((?<instrument>.*)\)");
+                    Match match = pattern.Match(person);
+
+                    // If the performer doesn't have any instrument/role associated, it won't match. In that case, chances are it's simply a band name, so we skip it.
+                    if (match.Success)
+                    {
+                        people.Add(new BaseItemPerson
+                        {
+                            Name = match.Groups["name"].Value,
+                            Type = PersonType.Actor,
+                            Role = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(match.Groups["instrument"].Value)
+                        });
+                    }
+                }
+            }
+
             // Check for writer some music is tagged that way as alternative to composer/lyricist
             if (tags.TryGetValue("writer", out var writer) && !string.IsNullOrWhiteSpace(writer))
             {

+ 4 - 1
tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeResultNormalizerTests.cs

@@ -107,7 +107,7 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
             Assert.Equal(2020, res.ProductionYear);
             Assert.True(res.PremiereDate.HasValue);
             Assert.Equal(DateTime.Parse("2020-10-26T00:00Z", DateTimeFormatInfo.CurrentInfo).ToUniversalTime(), res.PremiereDate);
-            Assert.Equal(4, res.People.Length);
+            Assert.Equal(18, res.People.Length);
             Assert.Equal("Krysta Youngs", res.People[0].Name);
             Assert.Equal(PersonType.Composer, res.People[0].Type);
             Assert.Equal("Julia Ross", res.People[1].Name);
@@ -116,6 +116,9 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
             Assert.Equal(PersonType.Composer, res.People[2].Type);
             Assert.Equal("Ji-hyo Park", res.People[3].Name);
             Assert.Equal(PersonType.Lyricist, res.People[3].Type);
+            Assert.Equal("Yiwoomin", res.People[4].Name);
+            Assert.Equal(PersonType.Actor, res.People[4].Type);
+            Assert.Equal("Electric Piano", res.People[4].Role);
             Assert.Equal(4, res.Genres.Length);
             Assert.Contains("Electronic", res.Genres);
             Assert.Contains("Trance", res.Genres);