Make LyricParser a field

pull/8381/head
1hitsong 2 years ago
parent 3ba8218e45
commit b442c79e62

@ -18,6 +18,8 @@ public class LrcLyricProvider : ILyricProvider
{ {
private readonly ILogger<LrcLyricProvider> _logger; private readonly ILogger<LrcLyricProvider> _logger;
private readonly LyricParser _lrcLyricParser;
private static readonly IReadOnlyList<string> _acceptedTimeFormats = new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }; private static readonly IReadOnlyList<string> _acceptedTimeFormats = new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" };
/// <summary> /// <summary>
@ -27,6 +29,7 @@ public class LrcLyricProvider : ILyricProvider
public LrcLyricProvider(ILogger<LrcLyricProvider> logger) public LrcLyricProvider(ILogger<LrcLyricProvider> logger)
{ {
_logger = logger; _logger = logger;
_lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -62,13 +65,11 @@ public class LrcLyricProvider : ILyricProvider
try try
{ {
// Parse and sort lyric rows lyricData = _lrcLyricParser.Decode(lrcFileContent);
LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
lyricData = lrcLyricParser.Decode(lrcFileContent);
} }
catch (Exception ex) 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; return null;
} }
@ -92,7 +93,12 @@ public class LrcLyricProvider : ILyricProvider
string metaDataFieldName = metaDataField[0][1..]; string metaDataFieldName = metaDataField[0][1..];
string metaDataFieldValue = metaDataField[1][..^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) if (sortedLyricData.Count == 0)

Loading…
Cancel
Save