Explorar o código

Use model properties for LRC metadata

1hitsong %!s(int64=2) %!d(string=hai) anos
pai
achega
0b86630be7

+ 1 - 1
MediaBrowser.Controller/Lyrics/LyricResponse.cs

@@ -10,7 +10,7 @@ public class LyricResponse
     /// <summary>
     /// Gets or sets Metadata.
     /// </summary>
-    public IDictionary<string, string>? Metadata { get; set; }
+    public Metadata? Metadata { get; set; }
 
     /// <summary>
     /// Gets or sets Lyrics.

+ 54 - 0
MediaBrowser.Controller/Lyrics/Metadata.cs

@@ -0,0 +1,54 @@
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.Lyrics;
+
+/// <summary>
+/// Metadata model.
+/// </summary>
+public class Metadata
+{
+    /// <summary>
+    /// Gets or sets Artist - [ar:The song artist].
+    /// </summary>
+    public string? Ar { get; set; }
+
+    /// <summary>
+    /// Gets or sets Album - [al:The album this song is on].
+    /// </summary>
+    public string? Al { get; set; }
+
+    /// <summary>
+    /// Gets or sets Title - [ti:The title of the song].
+    /// </summary>
+    public string? Ti { get; set; }
+
+    /// <summary>
+    /// Gets or sets Author - [au:Creator of the lyric data].
+    /// </summary>
+    public string? Au { get; set; }
+
+    /// <summary>
+    /// Gets or sets Length - [length:How long the song is].
+    /// </summary>
+    public string? Length { get; set; }
+
+    /// <summary>
+    /// Gets or sets By - [by:Creator of the LRC file].
+    /// </summary>
+    public string? By { get; set; }
+
+    /// <summary>
+    /// Gets or sets Offset - [offsec:+/- Timestamp adjustment in milliseconds].
+    /// </summary>
+    public string? Offset { get; set; }
+
+    /// <summary>
+    /// Gets or sets Creator - [re:The Software used to create the LRC file].
+    /// </summary>
+    public string? Re { get; set; }
+
+    /// <summary>
+    /// Gets or sets Version - [ve:The version of the Creator used].
+    /// </summary>
+    public string? Ve { get; set; }
+}

+ 1 - 0
MediaBrowser.Controller/MediaBrowser.Controller.csproj

@@ -18,6 +18,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <PackageReference Include="AutoMapper" Version="11.0.1" />
     <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
     <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
     <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />

+ 8 - 3
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Globalization;
 using System.Linq;
+using AutoMapper;
 using LrcParser.Model;
 using LrcParser.Parser;
 using MediaBrowser.Controller.Entities;
@@ -44,7 +45,8 @@ public class LrcLyricProvider : ILyricProvider
         List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
         List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
 
-        IDictionary<string, string> metaData = new Dictionary<string, string>();
+        // Must be <string, object> for automapper support
+        IDictionary<string, object> metaData = new Dictionary<string, object>();
         string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
 
         try
@@ -69,7 +71,7 @@ public class LrcLyricProvider : ILyricProvider
                     continue;
                 }
 
-                string metaDataFieldName = metaDataField[0][1..].Trim();
+                string metaDataFieldName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaDataField[0][1..].Trim().ToLowerInvariant());
                 string metaDataFieldValue = metaDataField[1][..^1].Trim();
 
                 metaData.Add(metaDataFieldName, metaDataFieldValue);
@@ -85,6 +87,9 @@ public class LrcLyricProvider : ILyricProvider
             return null;
         }
 
+        var config = new MapperConfiguration(cfg => { });
+        var mapper = config.CreateMapper();
+
         for (int i = 0; i < sortedLyricData.Count; i++)
         {
             var timeData = sortedLyricData[i].TimeTags.First().Value;
@@ -99,7 +104,7 @@ public class LrcLyricProvider : ILyricProvider
 
         if (metaData.Any())
         {
-           return new LyricResponse { Metadata = metaData, Lyrics = lyricList };
+           return new LyricResponse { Metadata = mapper.Map<Metadata>(metaData), Lyrics = lyricList };
         }
 
         return new LyricResponse { Lyrics = lyricList };