diff options
| author | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-17 19:47:29 -0400 |
|---|---|---|
| committer | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-17 19:47:29 -0400 |
| commit | 0b86630be7737e28555f0132322ecd02915284c5 (patch) | |
| tree | 18dd86164931fbda8a0d550422583d72082aa410 | |
| parent | 64b013b121f472d2658e5f2b3a672c4c4ced342d (diff) | |
Use model properties for LRC metadata
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/Metadata.cs | 54 | ||||
| -rw-r--r-- | MediaBrowser.Controller/MediaBrowser.Controller.csproj | 1 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 11 |
4 files changed, 64 insertions, 4 deletions
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs index e18cb1101..adc13050e 100644 --- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs +++ b/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. diff --git a/MediaBrowser.Controller/Lyrics/Metadata.cs b/MediaBrowser.Controller/Lyrics/Metadata.cs new file mode 100644 index 000000000..114b56777 --- /dev/null +++ b/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; } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index d4e025a43..c08e276dc 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/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" /> diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index db87d9236..b527c5303 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<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 }; |
