mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Use model properties for LRC metadata
This commit is contained in:
parent
64b013b121
commit
0b86630be7
@ -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
MediaBrowser.Controller/Lyrics/Metadata.cs
Normal file
54
MediaBrowser.Controller/Lyrics/Metadata.cs
Normal file
@ -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; }
|
||||
}
|
@ -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" />
|
||||
|
@ -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 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user