From b442c79e620d2bdbb9007038371b75fe41b7cd8a Mon Sep 17 00:00:00 2001 From: 1hitsong <3330318+1hitsong@users.noreply.github.com> Date: Mon, 19 Sep 2022 20:24:05 -0400 Subject: [PATCH] Make LyricParser a field --- MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index 3657cf8943..3177abb963 100644 --- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs +++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs @@ -18,6 +18,8 @@ public class LrcLyricProvider : ILyricProvider { private readonly ILogger _logger; + private readonly LyricParser _lrcLyricParser; + private static readonly IReadOnlyList _acceptedTimeFormats = new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }; /// @@ -27,6 +29,7 @@ public class LrcLyricProvider : ILyricProvider public LrcLyricProvider(ILogger logger) { _logger = logger; + _lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser(); } /// @@ -62,13 +65,11 @@ public class LrcLyricProvider : ILyricProvider try { - // Parse and sort lyric rows - LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser(); - lyricData = lrcLyricParser.Decode(lrcFileContent); + lyricData = _lrcLyricParser.Decode(lrcFileContent); } catch (Exception ex) { - _logger.LogError(ex, "Error parsing lyric data from {Provider}", Name); + _logger.LogError(ex, "Error parsing lyric file {LyricFilePath} from {Provider}", lyricFilePath, Name); return null; } @@ -92,7 +93,12 @@ public class LrcLyricProvider : ILyricProvider string metaDataFieldName = metaDataField[0][1..]; string metaDataFieldValue = metaDataField[1][..^1]; - fileMetaData.Add(metaDataFieldName, metaDataFieldValue); + if (string.IsNullOrEmpty(metaDataFieldName) || string.IsNullOrEmpty(metaDataFieldValue)) + { + continue; + } + + fileMetaData[metaDataFieldName] = metaDataFieldValue; } if (sortedLyricData.Count == 0)