diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs index e18cb1101e..adc13050ee 100644 --- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs +++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs @@ -10,7 +10,7 @@ public class LyricResponse /// /// Gets or sets Metadata. /// - public IDictionary? Metadata { get; set; } + public Metadata? Metadata { get; set; } /// /// Gets or sets Lyrics. diff --git a/MediaBrowser.Controller/Lyrics/Metadata.cs b/MediaBrowser.Controller/Lyrics/Metadata.cs new file mode 100644 index 0000000000..114b56777a --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/Metadata.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Lyrics; + +/// +/// Metadata model. +/// +public class Metadata +{ + /// + /// Gets or sets Artist - [ar:The song artist]. + /// + public string? Ar { get; set; } + + /// + /// Gets or sets Album - [al:The album this song is on]. + /// + public string? Al { get; set; } + + /// + /// Gets or sets Title - [ti:The title of the song]. + /// + public string? Ti { get; set; } + + /// + /// Gets or sets Author - [au:Creator of the lyric data]. + /// + public string? Au { get; set; } + + /// + /// Gets or sets Length - [length:How long the song is]. + /// + public string? Length { get; set; } + + /// + /// Gets or sets By - [by:Creator of the LRC file]. + /// + public string? By { get; set; } + + /// + /// Gets or sets Offset - [offsec:+/- Timestamp adjustment in milliseconds]. + /// + public string? Offset { get; set; } + + /// + /// Gets or sets Creator - [re:The Software used to create the LRC file]. + /// + public string? Re { get; set; } + + /// + /// Gets or sets Version - [ve:The version of the Creator used]. + /// + public string? Ve { get; set; } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index d4e025a43e..c08e276dcf 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -18,6 +18,7 @@ + diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index db87d92368..b527c5303c 100644 --- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs +++ b/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 lyricList = new List(); List sortedLyricData = new List(); - IDictionary metaData = new Dictionary(); + // Must be for automapper support + IDictionary metaData = new Dictionary(); 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), Lyrics = lyricList }; } return new LyricResponse { Lyrics = lyricList };