From a52d108af6b8519715bc7005e7db3f1a116760bc Mon Sep 17 00:00:00 2001 From: 1hitsong <3330318+1hitsong@users.noreply.github.com> Date: Sun, 18 Sep 2022 11:47:57 -0400 Subject: [PATCH] Remove automapper tool --- .../Lyrics/LyricMetadata.cs | 52 +++++++++++++ .../Lyrics/LyricResponse.cs | 2 +- MediaBrowser.Controller/Lyrics/Metadata.cs | 54 ------------- .../MediaBrowser.Controller.csproj | 1 - .../Lyric/LrcLyricProvider.cs | 78 ++++++++++++++++--- 5 files changed, 120 insertions(+), 67 deletions(-) create mode 100644 MediaBrowser.Controller/Lyrics/LyricMetadata.cs delete mode 100644 MediaBrowser.Controller/Lyrics/Metadata.cs diff --git a/MediaBrowser.Controller/Lyrics/LyricMetadata.cs b/MediaBrowser.Controller/Lyrics/LyricMetadata.cs new file mode 100644 index 0000000000..36a833f85c --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/LyricMetadata.cs @@ -0,0 +1,52 @@ +namespace MediaBrowser.Controller.Lyrics; + +/// +/// LyricMetadata model. +/// +public class LyricMetadata +{ + /// + /// Gets or sets Artist - The song artist. + /// + public string? Artist { get; set; } + + /// + /// Gets or sets Album - The album this song is on. + /// + public string? Album { get; set; } + + /// + /// Gets or sets Title - The title of the song. + /// + public string? Title { get; set; } + + /// + /// Gets or sets Author - Creator of the lyric data. + /// + public string? Author { get; set; } + + /// + /// Gets or sets Length - How long the song is. + /// + public string? Length { get; set; } + + /// + /// Gets or sets By - Creator of the LRC file. + /// + public string? By { get; set; } + + /// + /// Gets or sets Offset - Offset:+/- Timestamp adjustment in milliseconds. + /// + public string? Offset { get; set; } + + /// + /// Gets or sets Creator - The Software used to create the LRC file. + /// + public string? Creator { get; set; } + + /// + /// Gets or sets Version - The version of the Creator used. + /// + public string? Version { get; set; } +} diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs index adc13050ee..9892483889 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 Metadata? Metadata { get; set; } + public LyricMetadata? Metadata { get; set; } /// /// Gets or sets Lyrics. diff --git a/MediaBrowser.Controller/Lyrics/Metadata.cs b/MediaBrowser.Controller/Lyrics/Metadata.cs deleted file mode 100644 index 114b56777a..0000000000 --- a/MediaBrowser.Controller/Lyrics/Metadata.cs +++ /dev/null @@ -1,54 +0,0 @@ -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 c08e276dcf..d4e025a43e 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -18,7 +18,6 @@ - diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index b527c5303c..4cc06dac8d 100644 --- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs +++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs @@ -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 lyricList = new List(); List sortedLyricData = new List(); - // Must be for automapper support - IDictionary metaData = new Dictionary(); + IDictionary fileMetaData = new Dictionary(); 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), 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 }; } + + /// + /// Converts metadata from an LRC file to LyricMetadata properties. + /// + /// The metadata from the LRC file. + /// A lyricMetadata object with mapped property data. + private LyricMetadata MapMetadataValues(IDictionary 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; + + } }