Remove automapper tool
This commit is contained in:
parent
0b86630be7
commit
a52d108af6
52
MediaBrowser.Controller/Lyrics/LyricMetadata.cs
Normal file
52
MediaBrowser.Controller/Lyrics/LyricMetadata.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// LyricMetadata model.
|
||||
/// </summary>
|
||||
public class LyricMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets Artist - The song artist.
|
||||
/// </summary>
|
||||
public string? Artist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Album - The album this song is on.
|
||||
/// </summary>
|
||||
public string? Album { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Title - The title of the song.
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Author - Creator of the lyric data.
|
||||
/// </summary>
|
||||
public string? Author { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Length - How long the song is.
|
||||
/// </summary>
|
||||
public string? Length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets By - Creator of the LRC file.
|
||||
/// </summary>
|
||||
public string? By { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Offset - Offset:+/- Timestamp adjustment in milliseconds.
|
||||
/// </summary>
|
||||
public string? Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Creator - The Software used to create the LRC file.
|
||||
/// </summary>
|
||||
public string? Creator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Version - The version of the Creator used.
|
||||
/// </summary>
|
||||
public string? Version { get; set; }
|
||||
}
|
|
@ -10,7 +10,7 @@ public class LyricResponse
|
|||
/// <summary>
|
||||
/// Gets or sets Metadata.
|
||||
/// </summary>
|
||||
public Metadata? Metadata { get; set; }
|
||||
public LyricMetadata? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets Lyrics.
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
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,7 +18,6 @@
|
|||
</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" />
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
using System;
|
||||
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;
|
||||
using MediaBrowser.Controller.Lyrics;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MediaBrowser.Providers.Lyric;
|
||||
|
||||
|
@ -45,8 +44,7 @@ public class LrcLyricProvider : ILyricProvider
|
|||
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
|
||||
List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
|
||||
|
||||
// Must be <string, object> for automapper support
|
||||
IDictionary<string, object> metaData = new Dictionary<string, object>();
|
||||
IDictionary<string, string> fileMetaData = new Dictionary<string, string>();
|
||||
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
|
||||
|
||||
try
|
||||
|
@ -71,10 +69,10 @@ public class LrcLyricProvider : ILyricProvider
|
|||
continue;
|
||||
}
|
||||
|
||||
string metaDataFieldName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaDataField[0][1..].Trim().ToLowerInvariant());
|
||||
string metaDataFieldName = metaDataField[0][1..].Trim().ToLowerInvariant();
|
||||
string metaDataFieldValue = metaDataField[1][..^1].Trim();
|
||||
|
||||
metaData.Add(metaDataFieldName, metaDataFieldValue);
|
||||
fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -87,9 +85,6 @@ 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;
|
||||
|
@ -102,11 +97,72 @@ public class LrcLyricProvider : ILyricProvider
|
|||
lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
|
||||
}
|
||||
|
||||
if (metaData.Any())
|
||||
if (fileMetaData.Any())
|
||||
{
|
||||
return new LyricResponse { Metadata = mapper.Map<Metadata>(metaData), Lyrics = lyricList };
|
||||
// Map metaData values from LRC file to LyricMetadata properties
|
||||
LyricMetadata lyricMetadata = MapMetadataValues(fileMetaData);
|
||||
|
||||
return new LyricResponse { Metadata = lyricMetadata, Lyrics = lyricList };
|
||||
}
|
||||
|
||||
return new LyricResponse { Lyrics = lyricList };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts metadata from an LRC file to LyricMetadata properties.
|
||||
/// </summary>
|
||||
/// <param name="metaData">The metadata from the LRC file.</param>
|
||||
/// <returns>A lyricMetadata object with mapped property data.</returns>
|
||||
private LyricMetadata MapMetadataValues(IDictionary<string, string> metaData)
|
||||
{
|
||||
LyricMetadata lyricMetadata = new LyricMetadata();
|
||||
|
||||
if (metaData.TryGetValue("ar", out var artist) && artist is not null)
|
||||
{
|
||||
lyricMetadata.Artist = artist;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("al", out var album) && album is not null)
|
||||
{
|
||||
lyricMetadata.Album = album;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("ti", out var title) && title is not null)
|
||||
{
|
||||
lyricMetadata.Title = title;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("au", out var author) && author is not null)
|
||||
{
|
||||
lyricMetadata.Author = author;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("length", out var length) && length is not null)
|
||||
{
|
||||
lyricMetadata.Length = length;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("by", out var by) && by is not null)
|
||||
{
|
||||
lyricMetadata.By = by;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("offset", out var offset) && offset is not null)
|
||||
{
|
||||
lyricMetadata.Offset = offset;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("re", out var creator) && creator is not null)
|
||||
{
|
||||
lyricMetadata.Creator = creator;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("ve", out var version) && version is not null)
|
||||
{
|
||||
lyricMetadata.Version = version;
|
||||
}
|
||||
|
||||
return lyricMetadata;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user